我有两个 Tikz 图 - 让我们用 $D$ 和 $D'$ 表示它们的代码。现在我想将它们显示在同一行中,所以我将它们对齐。也就是说我写
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{align}
D & & D'
\end{align*}
\end{document}
此外,我想在每个图表下添加一个标题。我尝试使用标题软件,但似乎在对齐环境中不起作用。我该如何解决这个问题?
答案1
这里有一个方法,采纳了评论,主要是来自伊格纳西:
请查看ctan 子图中的软件包文档了解详情。
\documentclass[10pt,a4paper]{article}
\usepackage{tikz} % for Tikz
\usepackage{lipsum} % some blindtext
\usepackage{subfigure} % assuming both figures belong together somehow
\begin{document}
\lipsum[10] See figure \ref{fig}.
\begin{figure}[!h]
\centering
\subfigure[Left demo]{% "split", just to show the structure
\tikz{% <<< put those % to avoid insertion of unwanted spaces, i.e. shifts
\draw (0,0) rectangle (3,2);%
}%
}
\hspace{2cm}% some extra horizontal separation
\subfigure[Right demo]{\tikz{\draw[fill=green!20] (0,0) rectangle (2,3);}}
\caption{Two demo figures with Tikz}\label{fig}
\end{figure}
\lipsum[11]
\end{document}
答案2
您的问题不清楚您喜欢如何展示您的图表。带标题还是不带标题?作为图中的子图还是两个独立的图?还是带有两张图片的图?因此,下面的 MWE(最小工作示例)包含所有列出的三种场景:
\documentclass{article} % or some other suitable document class
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\lipsum[66]
\begin{figure}[ht]
\centering
\subfloat[Left demo \label{subfig:a}]{\tikz\node[draw] {left subfigure};}
\hfil
\subfloat[Right demo \label{subfig:b}]{\tikz\node[draw] {right subfigure};}
\caption{As two sub figures drawn with Ti*k*Z}\
\label{fig}
\end{figure}
As you can see in subfigure \ref{subfig:a} in figure \ref{fig} \dots
\begin{figure}[ht]
\centering
\begin{minipage}{0.45\linewidth}\centering
\tikz\node[draw] {left figure};
\caption{Your left figure drawn by Ti*k*Z package}
\label{fig:a}
\end{minipage}
\hfil
\begin{minipage}{0.45\linewidth}\centering
\tikz\node[draw] {right figure};
\caption{Your right figure drawn by Ti*k*Z package}
\label{fig:b}
\end{minipage}
\end{figure}
As you can see in figure \ref{fig:a} and figure \ref{fig:b} \dots
At the end also example, when sub figures haven't own captions:
\begin{figure}[ht]
\centering
\tikz\node[draw, text width=0.4\linewidth] {left figure drawn using Ti*k*Z package};
\hfil
\tikz\node[draw, text width=0.4\linewidth] {right figure drawn using Ti*k*Z package};
\caption{As two images in figure, drawn with Ti*k*Z}
\label{fig:3}
\end{figure}
\end{document}
(红线仅显示文本块区域)