我希望我的图形/tikz 图形之间正好有 12.5 毫米的距离。我该怎么做?

我希望我的图形/tikz 图形之间正好有 12.5 毫米的距离。我该怎么做?

对于一个项目,我应该绘制具有边和顶点的不同图形。该项目的要点之一是图形之间的距离应该正好是 12.5 毫米,但我根本找不到办法来实现这一点。我已经尝试了几件事:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[margin=2.625cm]{geometry}
\usepackage{subcaption}



\begin{document}


\begin{tikzpicture}
\draw (0,0) -- (3,0);
\draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (0.7,0) circle [radius=0.05];
\draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (2.3,0) circle [radius=0.05];

\draw (4.25, 0) -- (7.25, 0);
\draw (4.95,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (4.95,0) circle [radius=0.05];
\draw (6.55,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (6.55,0) circle [radius=0.05];

\draw (8.5, 0) --  (11.5,0);
\draw (9.2,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (9.2,0) circle [radius=0.05];
\draw (10.8,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (10.8,0) circle [radius=0.05];

\draw (12.75, 0) -- (15.75, 0);
\draw (13.45,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (13.45,0) circle [radius=0.05];
\draw (15.05,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (15.05,0) circle [radius=0.05];
\end{tikzpicture}



\end{document}

但是,我还需要能够在其下方写一个标题。然后我尝试将它们制作成几个图形、子图形,我尝试使用 minipage,但似乎都无法确保图形之间正好有 12.5 毫米。我该如何解决这个问题?还有没有办法确保图形之间的垂直距离为 12.5 毫米?谢谢。

答案1

子标题使用四个宽度为 3cm 的空心正方形创建\subcaptionbox,每个正方形之间相隔 1.25cm 的水平间距,就像中的四幅画的tikzpicture排列方式一样。

\documentclass{article}
% \usepackage{graphicx} % loaded by tikz
\usepackage{tikz}
% \usetikzlibrary{positioning} % not used in this example
\usepackage[margin=2.625cm]{geometry}
\usepackage{subcaption}

\begin{document}

\begin{figure}
  \centering
  \begin{tikzpicture}
    \newcommand\mypic{
      \draw (0,0) -- (3,0);
      % do you really need draw _and_ fill, or just fill?
      \draw[fill] (0.7,0) circle [radius=0.05]
        node[above, xshift=-0.2cm, font=\small] {0};
      \draw[fill] (2.3,0) circle [radius=0.05]
        node[above, xshift=0.2cm, font=\small] {1};
    }

    \mypic
    \tikzset{xshift=4.25cm}
    \mypic
    \tikzset{xshift=4.25cm}
    \mypic
    \tikzset{xshift=4.25cm}
    \mypic
  \end{tikzpicture}
  % adjust vertical spacing
  \par\vspace{-5pt}
  % emulate the width of each drawing and the separation between them
  \subcaptionbox{A}{\rule{3cm}{0pt}}\hspace{1.25cm}%
  \subcaptionbox{B}{\rule{3cm}{0pt}}\hspace{1.25cm}%
  \subcaptionbox{C}{\rule{3cm}{0pt}}\hspace{1.25cm}%
  \subcaptionbox{D}{\rule{3cm}{0pt}}%

  \caption{Title}
\end{figure}

\end{document}

在此处输入图片描述

这个显示tikzpicture\subcaptionboxes 确实是对齐的,使用四个“X”作为标记: 在此处输入图片描述

答案2

这演示了如何使用范围在本地移动原点。

虽然指定子标题的宽度很重要,但只有在需要换行文本时它才需要准确。

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\usepackage[margin=2.625cm, showframe]{geometry}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\coordinate (origin) at (0,0);
\begin{scope}[shift=(origin), local bounding box=AA]
\draw (0,0) -- (3,0);
\draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (0.7,0) circle [radius=0.05];
\draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (2.3,0) circle [radius=0.05];
\end{scope}

\coordinate (offset) at ($(origin)-(AA.west)$);% location of origin relative to local bounding box
\path (AA.east) ++ (12.5mm,0) ++ (offset) coordinate (origin);

\begin{scope}[shift=(origin) ,local bounding box=BB]
\draw (0,0) -- (3,0);
\draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (0.7,0) circle [radius=0.05];
\draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (2.3,0) circle [radius=0.05];
\end{scope}

\path (BB.east) ++ (12.5mm,0) ++ (offset) coordinate (origin);

\begin{scope}[shift=(origin) ,local bounding box=CC]
\draw (0,0) -- (3,0);
\draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (0.7,0) circle [radius=0.05];
\draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (2.3,0) circle [radius=0.05];
\end{scope}

\path (CC.east) ++ (12.5mm,0) ++ (offset) coordinate (origin);

\begin{scope}[shift=(origin) ,local bounding box=DD]
\draw (0,0) -- (3,0);
\draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
\fill (0.7,0) circle [radius=0.05];
\draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
\fill (2.3,0) circle [radius=0.05];
\end{scope}
% show local bounding boxes
\draw[red] (AA.south west) rectangle (AA.north east)
  (BB.south west) rectangle (BB.north east)
  (CC.south west) rectangle (CC.north east)
  (DD.south west) rectangle (DD.north east);
% subcaptions
\begin{pgfinterruptboundingbox}% not strictly necessary
\path ($(AA.north east)-(AA.south west)$);
\pgfgetlastxy{\AAwidth}{\AAheight}%
\global\let\AAwidth=\AAwidth
\end{pgfinterruptboundingbox}

%\node[above] at (current bounding box.north) {\AAwidth};
\node[below, text width=\AAwidth, inner sep=0pt] at (AA.south) {\subcaption{}};
\node[below, text width=\AAwidth, inner sep=0pt] at (BB.south) {\subcaption{}};
\node[below, text width=\AAwidth, inner sep=0pt] at (CC.south) {\subcaption{}};
\node[below, text width=\AAwidth, inner sep=0pt] at (DD.south) {\subcaption{}};
\end{tikzpicture}
\end{figure}

\end{document}

答案3

我会用四种不同的 TiZ 图片。不要忘记%行末的,就像下面的代码一样。

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[margin=2.625cm]{geometry}
\usepackage{subcaption}



\begin{document}

\begin{figure}[htp]

\subcaptionbox{A}{% <--- important
  \begin{tikzpicture}
  \draw (0,0) -- (3,0);
  \draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
  \fill (0.7,0) circle [radius=0.05];
  \draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
  \fill (2.3,0) circle [radius=0.05];
  \draw (0,0.5) -- (3,0.5);
  \end{tikzpicture}% <--- important
}\hspace{12.5mm}% <--- important
\subcaptionbox{B}{%
  \begin{tikzpicture}
  \draw (0,-0.2) -- (3,-0.2);
  \draw (0,0) -- (3,0);
  \draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
  \fill (0.7,0) circle [radius=0.05];
  \draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
  \fill (2.3,0) circle [radius=0.05];
  \end{tikzpicture}%
}\hspace{12.5mm}%
\subcaptionbox{C}{%
  \begin{tikzpicture}
  \draw (0,0) -- (3,0);
  \draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
  \fill (0.7,0) circle [radius=0.05];
  \draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
  \fill (2.3,0) circle [radius=0.05];
  \end{tikzpicture}%
}\hspace{12.5mm}%
\subcaptionbox{D}{%
  \begin{tikzpicture}
  \draw (0,0) -- (3,0);
  \draw (0.7,0) circle [radius=0.05] node[above, xshift=-0.2cm, font=\small]{0};
  \fill (0.7,0) circle [radius=0.05];
  \draw (2.3,0) circle [radius=0.05] node[above, xshift=0.2cm, font=\small]{1};
  \fill (2.3,0) circle [radius=0.05];
  \end{tikzpicture}%
}

\caption{Global caption}

\end{figure}

\end{document}

在此处输入图片描述

相关内容