如何让框(图表)中的内容居中?

如何让框(图表)中的内容居中?

如何让框(图表)中的内容居中?

在此处输入图片描述

\documentclass[12pt, tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                backgrounds,
                chains,
                fit,
                positioning}

\begin{document}

\begin{tikzpicture}[
node distance = 3mm and 0mm,
  start chain = going below,
   arr/.style = {thick, -{Triangle[angle=60:3pt 2]}, semithick},
   box/.style = {draw, dashed, fill=white,
                 minimum height=#1, text width=64mm,
                 inner sep=2mm, font=\small\sffamily,},
 sound/.style = {box, solid,
                 text width=36mm,  
                %   text width=30mm,  
                 on chain, join=by arr},
                        ]
\node (f1) [box=24mm] {};
    \node (f1c) [sound, above=of f1.south]        {ABC};

\end{tikzpicture}
\end{document}

我曾尝试过:

   box/.style = {draw, dashed, fill=white,
                 minimum height=#1, text width=64mm,
                 inner sep=2mm, font=\small\sffamily,},

通过添加centre,它不起作用

答案1

如果您希望所有sound框都包含居中的节点内容,请添加align=centersound的样式定义中:

\documentclass[12pt, tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                backgrounds,
                chains,
                fit,
                positioning}

\begin{document}

\begin{tikzpicture}[
node distance = 3mm and 0mm,
  start chain = going below,
   arr/.style = {thick, -{Triangle[angle=60:3pt 2]}, semithick},
   box/.style = {draw, dashed, fill=white,
                 minimum height=#1, text width=64mm,
                 inner sep=2mm, font=\small\sffamily,},
 sound/.style = {box, solid,
                 text width=36mm, 
                %   text width=30mm,
                 align=center,
                 on chain, join=by arr},
                        ]
\node (f1) [box=24mm] {};
    \node (f1c) [sound, above=of f1.south]        {ABC};

\end{tikzpicture}
\end{document}

在此处输入图片描述

在这种情况下,当您只想将一个节点内容居中时,请将此选项添加到节点的选项中:

\node (f1) [box=24mm] {};
    \node (f1c) [sound, align=center,
                 above=of f1.south]        {ABC};

相关内容