我有一个带有 2 个节点的 tikzpicture。一个节点是图像,另一个节点是轴标签。我想将标题相对于图像节点居中,而不是放在完整的 tikzpicture 上。请帮忙,下面是我的 latex,
\begin{figure}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics {}}
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$}
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize}
\captionof{figure}{This is some junk text as caption for figure 1}
\end{minipage}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics {}}
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$}
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize}
\captionof{figure}{This is some junk text as caption for figure 2}
\end{minipage}
\end{figure}
答案1
在image
节点后添加\useasboundingbox (image.south east) rectangle (image.north west);
。此后添加的任何内容都不会考虑 的边界框tikzpicture
。
为了给带有分数的节点腾出空间,我减少了 sa 位的宽度minipage
,并\hfill
在它们之间添加了。还请注意,由于您在环境中figure
,因此不需要使用\captionof
。
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tikz,caption}
\begin{document}
\begin{figure}
\captionsetup{type=figure,font=footnotesize}
\begin{minipage}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}
\node [inner sep=0pt] (image) at (0,0) {\includegraphics{}};
\useasboundingbox (image.south east) rectangle (image.north west);
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\caption{This is some junk text as caption for figure 1}
\end{minipage}\hfill
\begin{minipage}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}
\node [inner sep=0pt] (image) at (0,0) {\includegraphics{}};
\useasboundingbox (image.south east) rectangle (image.north west);
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\caption{This is some junk text as caption for figure 2}
\end{minipage}
\end{figure}
\end{document}
答案2
编辑:请看一下 Torbjørn 的解决方案,我相信它比我的更简单、更干净。
如果您想将标题置于整个 minipage/tikzpicture 的中心:这很容易。只需添加justification=centering
到您的\captionformat
。
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{figure}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=0.8\textwidth]{example-image}};
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize,justification=centering,format=plain}
\captionof{figure}{This is some junk text as caption for figure 1}
% Just for demo, you can remove these two lines
\noindent\rule{1pt}{6pt}
\noindent\rule{\textwidth}{1pt}
\end{minipage}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=0.8\textwidth]{example-image}};
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize,justification=centering,format=plain}
\captionof{figure}{This is some junk text as caption for figure 2}
% Just for demo, you can remove these two lines
\noindent\rule{1pt}{6pt}
\noindent\rule{\textwidth}{1pt}
\end{minipage}
\end{figure}
\end{document}
附加的线条表明标题位于小页面的中心。
如果您想将标题置于“真实”图像(我示例中的灰色框)的中心,那么您必须告诉标题您的图像从哪里开始和结束。这可以通过margin={<left>,<right>}
\captionsetup 的参数来实现。我在这里用 为我的灰色框做了这件事margin={1cm,0.4cm}
,但可能需要调整这些值以适合您的图像。
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{figure}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=0.8\textwidth]{example-image}};
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize,justification=centering,margin={1cm,0.4cm},format=plain}
\captionof{figure}{This is some junk text as caption for figure 1}
\noindent\rule{1pt}{6pt}
\noindent\rule{\textwidth}{1pt}
\end{minipage}
\begin{minipage}[b]{0.5\textwidth}
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=0.8\textwidth]{example-image}};
\node (ylabel) at (-3.25,0) {$\frac{test}{test}$};
\end{tikzpicture}
\captionsetup{type=figure,font=footnotesize,justification=centering,margin={1cm,0.4cm},format=plain}
\captionof{figure}{This is some junk text as caption for figure 2}
\noindent\rule{1pt}{6pt}
\noindent\rule{\textwidth}{1pt}
\end{minipage}
\end{figure}
\end{document}
如您所见,标题现在相对于图像位于中心\included
。