1. 问题在于您的不同边界框/尺寸不同tikzpicture。

1. 问题在于您的不同边界框/尺寸不同tikzpicture。

我试图将四个数字垂直和水平对齐。但尽管反复调整,我还是无法做到正确。

有人可以帮我吗?

这是 MWE——没有错误,但是数字没有按正确的比例显示。

\documentclass[12pt]{llncs}

\usepackage{fullpage}
\usepackage{graphicx}
 \pdfoutput=1
\usepackage{epsf}
\usepackage{epsfig}
\usepackage{epstopdf}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage[all]{xy}
%\pagestyle{empty}
\pagestyle{plain}
%\usepackage{algorithmic}
%\usepackage{algorithm}
\usepackage{hyperref}
\usepackage{nameref}
%\usepackage{MnSymbol}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subfig}

\begin{document}

\begin{figure}
\captionsetup[subfigure]{width=2in}
\begin{minipage}[t][4em][s]{.5\textwidth}
\subfloat[First]{
%\begin{subfigure}[b]{\textwidth}
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]

\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};


\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
%\draw (8) -- (7);
\draw[->] (5) -- (6);

\end{tikzpicture}
%\label{fig:sto}
} %%\qquad
%
%\bigskip
%
\subfloat[Second]{
\label{fig:st}
%\begin{subfgure}[b]{\textwidth}
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]

\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};


\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (2) to[out=-100,in=-150] (1);
%\draw (3) -- (2);
\draw[->] (3) -- (4);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (3);
%\draw (5) -- (4);
\draw[thick, dashed, ->] (2) to[out=-250,in=-350] (4);
\draw[thick, dashed, ->] (3) to[out=100,in=150] (1);    
%\draw (8) -- (7);
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=-100,in=-150] (5);


\end{tikzpicture}
}
\end{minipage}
\begin{minipage}[t][4em][s]{0.5\textwidth}
\subfloat[Third]{
%\begin{subfigure}[b]{\textwidth}
%\centering
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]

\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};


\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
%\draw (8) -- (7);
\draw[->] (5) -- (6);


\end{tikzpicture}
} %%\qquad
%
\subfloat[Fourth]{
\label{fig:ts}
%\begin{subfigure}
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]

\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};


\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (1);
%\draw (3) -- (2);
\draw[->] (3) -- (4);
\draw[thick, dashed, ->] (5) to[out=100,in=150] (1);
%\draw (5) -- (4);
\draw[thick, dashed, ->] (2) to[out=100,in=150] (5);
\draw[thick, dashed, ->] (4) to[out=-100,in=-160] (2);  
%\draw (8) -- (7);
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=100,in=150] (3);

\end{tikzpicture}
}
\end{minipage}
\end{figure}
\end{document}

答案1

编辑: 版本 2:新

  1. 在每个图形内定义一个边界框: \path[use as bounding box] (\xA,\yA ) rectangle (\xB,\yB); ...。参见15.8 建立边界框(p.176)。-x和 -值用( )y定义。它们应该适合最大的图形。要找到最佳拟合,您可以设置为并将边界框移动到合适的位置。\def\def\xA{-0.8}, \def\yA{-1.6},\def\xB{12.4},\def\yB{1.6}\drawORnot1

  2. 我添加了为每个图形绘制边界框的选项。只有当\drawboundingbox[<color>]{\drawORnot}时才会绘制,因此我使用了。\drawORnot1\ifthenelse

    \drawORnot= 1 -> 边界框开启

    \drawORnot= 2-> 边界框关闭)

  3. 缩放和简化是相同的(使用resizebox...),请参见下面的版本 1。 在此处输入图片描述

梅威瑟:

\documentclass[12pt,border=2cm]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{subfig}
%\usepackage{showframe}
\def\xA{-0.8}
\def\yA{-1.6}
\def\xB{12.4}
\def\yB{1.6}
\usepackage{pgfplots}

\def\drawORnot{1}% 1-> bounding box on; else -> bounding box off
\usepackage{ifthen}

\newcommand{\drawboundingbox}[2][red]{
  \ifthenelse{\equal{#2}{1}}
    {
    \draw [#1] (current bounding box.south west) rectangle (current bounding box.north east);
    }
    {
    %FALSE
    }%
}
\begin{document}

\begin{figure}[h!]
\centering
\subfloat[AAAA]{\label{fig:AAAA}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\path[use as bounding box] (\xA,\yA ) rectangle (\xB,\yB);
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
\draw[->] (5) -- (6);
\drawboundingbox[green]{\drawORnot}
\end{tikzpicture}
}
}%
\hfill 
\subfloat[BBBB]{\label{fig:BBBB}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\path[use as bounding box] (\xA,\yA ) rectangle (\xB,\yB);
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (2) to[out=-100,in=-150] (1);
\draw[->] (3) -- (4);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (3);
\draw[thick, dashed, ->] (2) to[out=-250,in=-350] (4);
\draw[thick, dashed, ->] (3) to[out=100,in=150] (1);    
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=-100,in=-150] (5);
\drawboundingbox[blue]{\drawORnot}
\end{tikzpicture}
}
}%
\hfill 
\subfloat[CCCC]{\label{fig:CCCC}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\path[use as bounding box] (\xA,\yA ) rectangle (\xB,\yB);
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
%%\draw (8) -- (7);
\draw[->] (5) -- (6);
\drawboundingbox[yellow]{\drawORnot}
\end{tikzpicture}
}
}%
\hfill 
\subfloat[DDDD]{\label{fig:DDDD}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\path[use as bounding box] (\xA,\yA ) rectangle (\xB,\yB);
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (1);
\draw[->] (3) -- (4);
\draw[thick, dashed, ->] (2) to[out=100,in=150] (5);
\draw[thick, dashed, ->] (4) to[out=-100,in=-160] (2);  
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=100,in=150] (3);
\drawboundingbox[black]{\drawORnot}
\end{tikzpicture}
}
}
\hfill 
\caption{Aligning figures in a table with colored bounding boxes (optional).}\label{fig:FIGone}
\end{figure}
\end{document}


版本 1:

1. 问题在于您的不同边界框/尺寸不同tikzpicture

所以我使用隐形\path来获得相同大小的图片。尺寸是第一次尝试,也许可以用同样的方式进行优化。因此您可以添加例如:

\path[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (-3,-3) grid (12,3);

... 到每一个tikzpicture。如果你替换\path为,\draw你可以看到尺寸。

2. 扩展

\resizebox{<horizontal size>}{<vertical size>}{...}(参见:4.3.2 缩放至所需大小,第 8 页)您可以设置 的水平和垂直尺寸tikzpicture。如果您希望tikzpicture按比例缩放 ,您可以指定其中一个尺寸并输入!另一个尺寸。我使用了6.5cm水平。

3. 简化

我删除了一些包以获得较小的 MWE,并将 documentclass 更改为 article。它还适用于llncs(下载:llncs.cls)。

\resizebox{6.5cm}{!}{
\begin{tikzpicture}
....
\end{tikzpicture}
}

对齐四个数字:

在此处输入图片描述

梅威瑟:

\documentclass[12pt]{article}
%\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{subfig}
\usepackage{showframe}
\begin{document}
\begin{figure}[h!]
\centering
\subfloat[AAAA]{\label{fig:AAAA}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
%%\draw (8) -- (7);
\draw[->] (5) -- (6);
\path[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (-3,-3) grid (12,3);
\end{tikzpicture}
}
}%
\hfill 
\subfloat[BBBB]{\label{fig:BBBB}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$s$};
\node (3) at (4.5, 0) {$s'$};
\node (4) at (7.5, 0) {$t'$};
\node (5) at (9.0, 0) {$t$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (2) to[out=-100,in=-150] (1);
%%\draw (3) -- (2);
\draw[->] (3) -- (4);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (3);
%%\draw (5) -- (4);
\draw[thick, dashed, ->] (2) to[out=-250,in=-350] (4);
\draw[thick, dashed, ->] (3) to[out=100,in=150] (1);    
%%\draw (8) -- (7);
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=-100,in=-150] (5);
\path[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (-3,-3) grid (12,3);
\end{tikzpicture}
}
}%
\hfill 
\subfloat[CCCC]{\label{fig:CCCC}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[->] (2) -- (3);
\draw[->] (3) -- (4);
\draw[->] (4) -- (5);
%%\draw (8) -- (7);
\draw[->] (5) -- (6);
\path[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (-3,-3) grid (12,3);
\end{tikzpicture}
}
}%
\hfill 
\subfloat[DDDD]{\label{fig:DDDD}
\resizebox{6.5cm}{!}{
\begin{tikzpicture}[every node/.style={circle, draw, scale=1.0, fill=gray!50}, scale=1.0, rotate = 180, xscale = -1]
\node (1) at (0, 0) {$a$};
\node (2) at (3.0, 0) {$t$};
\node (3) at (4.5, 0) {$t'$};
\node (4) at (7.5, 0) {$s'$};
\node (5) at (9.0, 0) {$s$};
\node (6) at (12.0, 0) {$b$};
\draw[->] (1) -- (2);
\draw[thick, dashed, ->] (4) to[out=-100,in=-150] (1);
%%\draw (3) -- (2);
\draw[->] (3) -- (4);
%\draw[thick, dashed, ->] (5) to[out=100,in=150] (1);
%%\draw (5) -- (4);
\draw[thick, dashed, ->] (2) to[out=100,in=150] (5);
\draw[thick, dashed, ->] (4) to[out=-100,in=-160] (2);  
%%\draw (8) -- (7);
\draw[->] (5) -- (6);
\draw[thick, dashed, ->] (6) to[out=100,in=150] (3);
\path[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (-3,-3) grid (12,3);
\end{tikzpicture}
}
}%
\hfill 
\caption{Aligning figures in a table}\label{fig:FIGone}
\end{figure}
\end{document}

相关内容