我使用以下代码来并排获取两个数字。代码 (MWE) 为:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{adjustbox}
\usepackage{float}
\begin{document}
\begin{figure}
\begin{minipage}[b]{0.49\textwidth}
\begin{figure}[H]
\begin{adjustbox}{width=1\textwidth}{
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex}]
\draw[my plot, color=black] (0,0) plot (\x,{ln(\x)});
\coordinate (start plot) at (0.1,{ln(0.1)});
\coordinate (end plot) at (5,{ln(5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{ln(\x)});
\coordinate (Uy) at (\y,{ln(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{ln(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[left,font=\scriptsize]{$u(px+(1-p)y)$} cycle;
\draw[my grid] (Up-mid) |- (origin) |- node[left,font=\scriptsize]{$pu(x)+(1-p)u(y)$} cycle;
\draw[my grid] (Up-mid) -- (Up-mid2);
\end{tikzpicture}}
\end{adjustbox}
\caption{Risk Aversion}\label{RA}
\end{figure}
\end{minipage}
\hfill
\begin{minipage}[b]{0.49\textwidth}
\begin{figure}[H]
\begin{adjustbox}{width=1\textwidth}{
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5.5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex}]
\draw[my plot, color=black] (0,0) plot (\x,{(\x)});
\coordinate (start plot) at (0,{(0)});
\coordinate (end plot) at (5.5,{(5.5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{(\x)});
\coordinate (Uy) at (\y,{(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[align=right,font=\scriptsize,xshift=-40pt]{$pu(x)+(1-p)u(y)=$\\$=u(px+(1-p)y)$} cycle;
\end{tikzpicture}}
\end{adjustbox}
\caption{Risk Neutrality}\label{RN}
\end{figure}
\end{minipage}
\end{figure}
\end{document}
结果是这样的:
虽然结果看起来不错,但我希望图表的大小完全相同;也就是说,轴的长度相同,字体大小相同,等等。但是,使用我的代码,我发现右侧的图表比左侧的图表稍大。我想避免这种情况。有人知道如何实现吗?恐怕我可能需要调整图形的轴,但无论我尝试什么,我都会故意失败。谢谢大家的帮助
答案1
首先,删除所有嵌套的figure
、adjustbox
和内容。然后使用 tikz 的和选项minipage
缩小较大的图(或者放大较小的图,如果你愿意的话)。对于 x 轴,你可以计算因子,因为域是给定的;它是 5/5.5=0.90909....对于 y 轴,我选择了实用方法,只是修改它直到它看起来一样。所以我们必须添加xscale
yscale
\begin{tikzpicture}[...,xscale=0.90909,yscale=0.75]
在第二个情节中。
这种缩放的优点\adjustbox
是仅缩放坐标系,而不缩放字体和线宽。
关于你的第二个问题,如何将两个数字并排放置,我可以参考两个并排的身影,LaTeX 图形并排显示以及许多类似的帖子。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex}]
\draw[my plot, color=black] (0,0) plot (\x,{ln(\x)});
\coordinate (start plot) at (0.1,{ln(0.1)});
\coordinate (end plot) at (5,{ln(5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{ln(\x)});
\coordinate (Uy) at (\y,{ln(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{ln(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[left,font=\scriptsize]{$u(px+(1-p)y)$} cycle;
\draw[my grid] (Up-mid) |- (origin) |- node[left,font=\scriptsize]{$pu(x)+(1-p)u(y)$} cycle;
\draw[my grid] (Up-mid) -- (Up-mid2);
\end{tikzpicture}
\quad
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5.5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex},xscale=0.90909,yscale=0.75]
\draw[my plot, color=black] (0,0) plot (\x,{(\x)});
\coordinate (start plot) at (0,{(0)});
\coordinate (end plot) at (5.5,{(5.5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{(\x)});
\coordinate (Uy) at (\y,{(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[align=right,font=\scriptsize,xshift=-40pt]{$pu(x)+(1-p)u(y)=$\\$=u(px+(1-p)y)$} cycle;
\end{tikzpicture}
\end{document}
编辑:这是用于容纳文章页面上的图表(包括标题)的包装器。我还使用技巧来移除长标签的宽度,以便\llap{...}
标签分别插入边距和其他图中。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{blindtext}
\begin{document}
\blindtext
\begin{figure}
\newcommand\commonscalefactor{0.64}%
\begin{minipage}[b]{\dimexpr0.5\textwidth-1em}
\centering
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex},scale=\commonscalefactor]
\draw[my plot, color=black] (0,0) plot (\x,{ln(\x)});
\coordinate (start plot) at (0.1,{ln(0.1)});
\coordinate (end plot) at (5,{ln(5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{ln(\x)});
\coordinate (Uy) at (\y,{ln(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{ln(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[left,font=\scriptsize]
{\llap{$u(px+(1-p)y)$}} cycle;
\draw[my grid] (Up-mid) |- (origin) |- node[left,font=\scriptsize]{\llap{$pu(x)+(1-p)u(y)$}} cycle;
\draw[my grid] (Up-mid) -- (Up-mid2);
\end{tikzpicture}\\
\caption{Risk Aversion}\label{RA}
\end{minipage}%
\hspace{2em}%
\begin{minipage}[b]{\dimexpr0.5\textwidth-1em}
\centering
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0.1:5.5}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex},xscale=0.90909*\commonscalefactor,yscale=0.75*\commonscalefactor]
\draw[my plot, color=black] (0,0) plot (\x,{(\x)});
\coordinate (start plot) at (0,{(0)});
\coordinate (end plot) at (5.5,{(5.5)});
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[above] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[right] {$\cdot$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (\x,{(\x)});
\coordinate (Uy) at (\y,{(\y)});
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{(\p*\x+(1-\p)*\y)});
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy);
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2);
\draw[my grid] (Ux) |- node[below,font=\scriptsize]{$x$} (origin) |- node[left,font=\scriptsize]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below,font=\scriptsize]{$y$} (origin) |- node[left,font=\scriptsize]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below, yshift=2.25pt, font=\scriptsize]{$px+(1-p)y$} (origin) |- node[align=right,font=\scriptsize,xshift=-0.5em]{\llap{$pu(x)+(1-p)u(y)=$}\\\llap{$=u(px+(1-p)y)$}} cycle;
\end{tikzpicture}\\
\caption{Risk Neutrality}\label{RN}
\end{minipage}%
\end{figure}
\end{document}