在绘制的图片下添加标题

在绘制的图片下添加标题

我有以下代码,可生成带有箭头的 3x3 网格。一些网格单元格中带有 #。

\begin{picture}(185,90)
\put(0,0){\framebox(30,30)}
\put(30,0){\framebox(30,30)}
\put(60,0){\framebox(30,30)}
\put(0,30){\framebox(30,30)}
\put(30,30){\framebox(30,30)}
\put(60,30){\framebox(30,30){\Large{\#}}}
\put(0,60){\framebox(30,30){\Large{\#}}}
\put(30,60){\framebox(30,30){\Large{\#}}}
\put(60,60){\framebox(30,30){\Large{\#}}}
\put(15,45){\vector(1,0){30}}
\end{picture}

使用 pdflatex 生成结果

我想在绘制的图片下添加标题。我该怎么做?我认为你不能在\开始{图片}。我也尝试过把它包裹在\开始{图}没有成功。

答案1

将 放入pictureminipage。这将允许它包含在figure环境中,从而允许\caption

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[ht]
\centering
\begin{minipage}{1.3in}
\begin{picture}(185,90)
\put(0,0){\framebox(30,30)}
\put(30,0){\framebox(30,30)}
\put(60,0){\framebox(30,30)}
\put(0,30){\framebox(30,30)}
\put(30,30){\framebox(30,30)}
\put(60,30){\framebox(30,30){\Large{\#}}}
\put(0,60){\framebox(30,30){\Large{\#}}}
\put(30,60){\framebox(30,30){\Large{\#}}}
\put(60,60){\framebox(30,30){\Large{\#}}}
\put(15,45){\vector(1,0){30}}
\end{picture}
\end{minipage}
\caption{Here is my caption.}
\end{figure}
\lipsum[2]
\end{document}

在此处输入图片描述

根据 OP 的评论,为了在一行上获得多幅图像,可以将相邻的minipages 放在同一行,只要它们不超过\linewidth

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[ht]
\centering
\begin{minipage}{1.3in}
\begin{picture}(185,90)
\put(0,0){\framebox(30,30)}
\put(30,0){\framebox(30,30)}
\put(60,0){\framebox(30,30)}
\put(0,30){\framebox(30,30)}
\put(30,30){\framebox(30,30)}
\put(60,30){\framebox(30,30){\Large{\#}}}
\put(0,60){\framebox(30,30){\Large{\#}}}
\put(30,60){\framebox(30,30){\Large{\#}}}
\put(60,60){\framebox(30,30){\Large{\#}}}
\put(15,45){\vector(1,0){30}}
\end{picture}
\end{minipage}
\begin{minipage}{1.3in}
\begin{picture}(185,90)
\put(0,0){\framebox(30,30)}
\put(30,0){\framebox(30,30)}
\put(60,0){\framebox(30,30)}
\put(0,30){\framebox(30,30)}
\put(30,30){\framebox(30,30)}
\put(60,30){\framebox(30,30){\Large{\#}}}
\put(0,60){\framebox(30,30){\Large{\#}}}
\put(30,60){\framebox(30,30){\Large{\#}}}
\put(60,60){\framebox(30,30){\Large{\#}}}
\put(15,45){\vector(1,0){30}}
\end{picture}
\end{minipage}
\caption{Here is my caption.}
\end{figure}
\lipsum[2]
\end{document}

在此处输入图片描述

答案2

你为图片设置的边界框太大了;而且你忘记了空框的空参数。请注意\Large 没有提出论点。

\documentclass{article}
\usepackage{pict2e}

\begin{document}

\begin{figure}
\centering

\begin{picture}(90,90)
\put(0,0){\framebox(30,30){}}
\put(30,0){\framebox(30,30){}}
\put(60,0){\framebox(30,30){}}
\put(0,30){\framebox(30,30){}}
\put(30,30){\framebox(30,30){}}
\put(60,30){\framebox(30,30){\Large\#}}
\put(0,60){\framebox(30,30){\Large\#}}
\put(30,60){\framebox(30,30){\Large\#}}
\put(60,60){\framebox(30,30){\Large\#}}
\put(15,45){\vector(1,0){30}}
\end{picture}

\caption{A picture}

\end{figure}

\end{document}

在此处输入图片描述

多张图片也没有问题:

\documentclass{article}
\usepackage{pict2e}

\begin{document}

\begin{figure}
\centering

\begin{picture}(90,90)
\put(0,0){\framebox(30,30){}}
\put(30,0){\framebox(30,30){}}
\put(60,0){\framebox(30,30){}}
\put(0,30){\framebox(30,30){}}
\put(30,30){\framebox(30,30){}}
\put(60,30){\framebox(30,30){\Large\#}}
\put(0,60){\framebox(30,30){\Large\#}}
\put(30,60){\framebox(30,30){\Large\#}}
\put(60,60){\framebox(30,30){\Large\#}}
\put(15,45){\vector(1,0){30}}
\end{picture}\qquad
\begin{picture}(90,90)
\put(0,0){\framebox(30,30){}}
\put(30,0){\framebox(30,30){}}
\put(60,0){\framebox(30,30){}}
\put(0,30){\framebox(30,30){}}
\put(30,30){\framebox(30,30){}}
\put(60,30){\framebox(30,30){\Large\#}}
\put(0,60){\framebox(30,30){\Large\#}}
\put(30,60){\framebox(30,30){\Large\#}}
\put(60,60){\framebox(30,30){\Large\#}}
\put(15,45){\vector(1,0){30}}
\end{picture}

\caption{A picture}

\end{figure}

\end{document}

在此处输入图片描述


绘制图形的更好方法是使用线条而不是框:这可以避免内线的“重复”。

\documentclass{article}
\usepackage{pict2e}

\begin{document}

\begin{figure}
\centering

\begin{picture}(90,90)
\polygon(0,0)(90,0)(90,90)(0,90)
\put(30,0){\line(0,1){90}}
\put(60,0){\line(0,1){90}}
\put(0,30){\line(1,0){90}}
\put(0,60){\line(1,0){90}}
\put(15,75){\makebox(0,0){\Large\#}}
\put(45,75){\makebox(0,0){\Large\#}}
\put(75,75){\makebox(0,0){\Large\#}}
\put(75,45){\makebox(0,0){\Large\#}}
\put(15,45){\vector(1,0){30}}
\end{picture}

\caption{A picture}

\end{figure}

\end{document}

注意边框是如何用 绘制的\polygon

在此处输入图片描述

答案3

这个问题已经很老了,但我想展示一下它的威力和简易性tikz

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}

\foreach \x in {0,1,2,3}
\draw (\x,0)--(\x,3)  (0,\x)--(3,\x);

\foreach \x/\y in {0.5/2.5,1.5/2.5,2.5/2.5,2.5/1.5}
\node at (\x,\y) {\Large{\#}};

\draw[-latex] (.5,1.5)--(1.5,1.5);

\end{tikzpicture}
\caption{A picture}
\end{figure}

\end{document}

在此处输入图片描述

相关内容