2

How to make the content in a box (diagram) be centred?

enter image description here

\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}

I had tried:

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

by adding centre, its not working

  • 2
    \node (f1c) [sound, above=of f1.south, align=center] (note: not centre) in the node works. – Marijn Aug 25 at 16:38
  • @Marijin. Thanks. it works – aan Aug 25 at 16:52
4

If you like to have all sound boxes with centered node contents, than add align=center to sound's style definition:

\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}

enter image description here

in the case, when you like to center only one node contets, than add this option to node's options:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.