我有七个图形:一个大(矩形)和六个小(正方形)。六个小正方形的大小总和等于大矩形的大小。我想将它们放置成如下形状:大矩形和由六个正方形组成的另一个矩形。我希望这两个矩形并排放置,而不是垂直形成一列。我当前的代码创建了一列:
\begin{figure}[]
\hfill
\begin{center}
\includegraphics[width=2.5cm]{rectangle}
\\
\includegraphics[width=1.0cm]{square}
\includegraphics[width=1.0cm]{square}
\\
\includegraphics[width=1.0cm]{square}
\includegraphics[width=1.0cm]{square}
\\
\includegraphics[width=1.0cm]{square}
\includegraphics[width=1.0cm]{square}
\end{center}
\caption{...}
\label{fig:4}
\end{figure}
我能做些什么?
谢谢。
答案1
按行和列排列材料的最简单方法是使用tabular
,在这种情况下是嵌套的。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{@{}cc@{}}% outer tabular
\begin{tabular}{@{}c@{}}% inner tabular for the big picture
\includegraphics[height=3cm,width=4cm]{duck}
\end{tabular}
&
\begin{tabular}{@{}cc@{}}% inner tabular for the squares
\includegraphics[height=1cm,width=1cm]{duck}&
\includegraphics[height=1cm,width=1cm]{duck}\\
\includegraphics[height=1cm,width=1cm]{duck}&
\includegraphics[height=1cm,width=1cm]{duck}\\
\includegraphics[height=1cm,width=1cm]{duck}&
\includegraphics[height=1cm,width=1cm]{duck}
\end{tabular}
\end{tabular}
\caption{Some ducks}\label{fig:ducks}
\end{figure}
\end{document}
如果您不想有空间,则需要进行一些更改:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\fincludegraphics}[2][]{% just for the example, to add frames
\begingroup\fboxsep=-\fboxrule
\fbox{\includegraphics[#1]{#2}}%
\endgroup
}
\begin{document}
\begin{figure}
\centering
\renewcommand{\arraystretch}{0}
\begin{tabular}{@{}cc@{}}% outer tabular
\begin{tabular}{@{}c@{}}% inner tabular for the big picture
\fincludegraphics[height=3cm,width=4cm]{duck}
\end{tabular}
&
\begin{tabular}{@{}c@{}c@{}}% inner tabular for the squares
\fincludegraphics[height=1cm,width=1cm]{duck}&
\fincludegraphics[height=1cm,width=1cm]{duck}\\
\fincludegraphics[height=1cm,width=1cm]{duck}&
\fincludegraphics[height=1cm,width=1cm]{duck}\\
\fincludegraphics[height=1cm,width=1cm]{duck}&
\fincludegraphics[height=1cm,width=1cm]{duck}
\end{tabular}
\\
\strut\footnotesize (a) & \footnotesize (b) % the subcaptions
\end{tabular}
\caption{Some ducks}\label{fig:ducks}
\end{figure}
\end{document}
我@{}
在所有列对之间添加了内容,并将数组拉伸设置为零,这样行就可以互相接触。
该\fincludegraphics
宏仅用于在图片周围添加边框,您应该使用普通的\includegraphics
。由于舍入误差,边框并不完整。
答案2
您可以将矩形放在一个地方minipage
,将六个正方形放在另一个地方。
\documentclass{article}
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\begin{document}
\begin{figure}
\centering
\begin{minipage}{2.5cm}
\includegraphics[width=2.5cm,height=1cm]{rectangle}
\end{minipage} % note: no line break after end of minipage
\begin{minipage}{2.05cm}
\includegraphics[width=1cm,height=1cm]{square}\hspace*{\fill}
\includegraphics[width=1cm,height=1cm]{square}
\includegraphics[width=1cm,height=1cm]{square}\hspace*{\fill}
\includegraphics[width=1cm,height=1cm]{square}
\includegraphics[width=1cm,height=1cm]{square}\hspace*{\fill}
\includegraphics[width=1cm,height=1cm]{square}
\end{minipage}
\caption{\dots} \label{fig:4}
\end{figure}
\end{document}