以特定节点集为中心

以特定节点集为中心

强制将一组节点置于页面中心的命令是什么?我正在尝试设计一个带有中心轴的图表,但在它旁边添加节点会导致轴偏心。

这里我希望红色部分居中

这里我希望红色部分居中

以下是代码:

\begin{figure}[H]

\begin{tikzpicture}
\node(engrenage)[contour]{
    \begin{tikzpicture}[node distance=4cm]
    %engrenage
    \node (cran1) [engrenage] {};
    \node (cran2) [engrenage, below of=cran1]{};
    \node (cran3) [engrenage, below of=cran2]{};
    \node (cran4) [engrenage, below of=cran3]{};
    \node (cran5) [engrenage, below of=cran4]{};
    \node (cran6) [engrenage, below of=cran5]{};
    
    \end{tikzpicture}
    
};

%cran
\node (cran_gauche) [cran, below of=cran3, xshift = -2cm, yshift = 10.15cm]{};
\node (cran_droit) [cran, below of =cran_gauche, xshift = 4cm, yshift = -0.8cm]{};
\end{tikzpicture}    
\caption{position repos}
\end{figure}

答案1

\centering假设您的图形是对称的,那么您可能缺少一个命令。

无论如何,您都有另一种方法来绘制类似的东西,但避免嵌套tikzpictures。主要区别在于使用positioningbackgroundsfit库。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning, backgrounds}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}[
    contour/.style={fill=red!30, draw, rounded corners},
    engrenage/.style={draw, fill=red!60, minimum width=2cm, minimum height=5mm, rounded corners},
    cran/.style={draw, fill=blue!30, minimum width=2.5cm, minimum height=5mm, rounded corners},
    node distance=2cm
]

    \node (cran1) [engrenage] {};
    \node (cran2) [engrenage, below = of cran1]{};
    \node (cran3) [engrenage, below = of cran2]{};
    \node (cran4) [engrenage, below = of cran3]{};
    \node (cran5) [engrenage, below = of cran4]{};
    \node (cran6) [engrenage, below = of cran5]{};

    \begin{scope}[on background layer]
    \node(engrenage)[contour, fit=(cran1) (cran6)] {};
    \end{scope}

%cran
\node (cran_gauche) [cran, below left = 0 and -2mm of cran3.south]{};
\node (cran_droit) [cran, above right = 0 and -2mm of cran4.north]{};
\end{tikzpicture}    
\caption{position repos}
\end{figure}

\end{document}

在此处输入图片描述

相关内容