Tikz:相关子图的正确对齐

Tikz:相关子图的正确对齐

这个问题可能和这个问题类似是否可以使用 tikz 图像制作图库?;但我不想“调整大小”或“调整”。两张图片应该表现得像在两张图片中都有 4 个点 (+/-1,+/-1)。也就是说,右侧图片应该更高(与左侧相应点的高度相同)。一种方法(如何?)是在 (1,1) 和 (-1,-1) 中定义两个无量纲的不可见点,这样 Tikz 就可以确保子弹(略微超出)不会被切断。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

\begin{figure}[hbt]
\begin{subfigure}[b]{0.48\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]
  \node[bullet] at (-1,-1)  (1){};
  \node[bullet] at (1,-1) (2){};
  \node[bullet] at (-1,1) (3){};
  \node[bullet] at (1,1)  (4){};
  \node[bullet] at (0,0)  (0){};
  \draw (0) -- (1);
  \draw (0) -- (2);
  \draw (0) -- (3);
  \draw (0) -- (4);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.48\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]
  \node[bullet] at (-1,1) (3){};
  \node[bullet] at (1,1)  (4){};
  \node[bullet] at (0,0)  (0){};
  \draw (0) -- (3);
  \draw (0) -- (4);
\end{tikzpicture}
\end{subfigure}

\caption{caption fig}
\label{fig:label}
\end{figure}

\end{document}

答案1

一种可能性是使用以下命令为两个图形定义相同的边界框\useasboundingbox (-1,-1)rectangle(1,1);

截屏

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

\begin{figure}[hbt]
\begin{subfigure}[b]{0.48\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]
 \useasboundingbox (-1,-1)rectangle(1,1);
  \node[bullet] at (-1,-1)  (1){};
  \node[bullet] at (1,-1) (2){};
  \node[bullet] at (-1,1) (3){};
  \node[bullet] at (1,1)  (4){};
  \node[bullet] at (0,0)  (0){};
  \draw (0) -- (1);
  \draw (0) -- (2);
  \draw (0) -- (3);
  \draw (0) -- (4);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.48\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]
\useasboundingbox (-1,-1)rectangle(1,1);
  \node[bullet] at (-1,1) (3){};
  \node[bullet] at (1,1)  (4){};
  \node[bullet] at (0,0)  (0){};
  \draw (0) -- (3);
  \draw (0) -- (4);
\end{tikzpicture}
\end{subfigure}

\caption{caption fig}
\label{fig:label}
\end{figure}

\end{document}

相关内容