wrapfig-with-equation

../_images/sphx_glr_wrapfig-with-equation.svg
\documentclass[preview]{jlreq}
%\usepackage[letterpaper]{geometry}
\usepackage[left=0.5cm, right=0.5cm, paperheight=120mm]{geometry}
%\pdfpageheight 11in
\usepackage[]{graphicx}

\usepackage{amsfonts,amssymb,amsmath}
\usepackage{mathrsfs}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{patterns}

\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}
\begin{wrapfigure}[]{r}[0pt]{0.4\textwidth}
\begin{tikzpicture}
\begin{axis}[
axis y line=left, axis x line=middle,
width=0.4\textwidth,
grid=both,
%ymin = 0, ymax = 1.2,
xmin = 0,xmax=5,
xtick ={0,1,2,3,4},
ytick ={0, ln(2), ln(3), ln(4)},
yticklabels={0, $\log 2$, $\log 3$, $\log 4$},
ticklabel style={font=\footnotesize},
label style={font=\footnotesize},
xlabel={$x$},
ylabel={$\log(x)$},
]
\addplot [domain=0.5:5,samples=100,black,very thick] {ln(x)};
\draw[pattern=north west lines, pattern color=gray] (1,0) -- (1,{ln(2)})--(2,{ln(2)}) --(1,0) circle;
\draw[pattern=north west lines, pattern color=gray] (2,{ln(2)}) -- (2,{ln(3)})--(3,{ln(3)}) --(2,{ln(2)}) circle;
\draw[pattern=north west lines, pattern color=gray] (3,{ln(3)}) -- (3,{ln(4)})--(4,{ln(4)}) --(3,{ln(3)})circle;
%\addplot [domain=0:5,samples=100,black,dashed,very thick] {1/(1+x)^2)};
%\legend{$P_l$,$P_i$};
\end{axis}
\end{tikzpicture}
\caption{$\log x$の図式}
\end{wrapfigure} %
\leavevmode% It must be need!
\begin{align}
\log n!  & \sim n \log n\\
\log n!  & =  n \log n -n + \mathcal{O}(\log n) 
\end{align}
\lipsum[1]
\end{document}