25

I am simply looking for a way to fix the size of my node (block) regardless of the text inside. I find several posts similar, but not the same. All the solutions given make use of minimum width=0.1cm line. But this is NOT the solution that I am looking for.

What I want is to take one block as the reference and make all the others same-size as that. I have tried the following, but failed.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
\begin{document}
\begin{tikzpicture}[block/.style={draw, fill=white, rectangle, minimum width=0.4*\columnwidth, anchor=south}, font=\small]
\node[block, minimum width=0.9*\columnwidth, minimum height = 5cm, fill=green, opacity=0.3, text opacity=1](sensors) at (0,0){};
\node[block, fill=white, minimum width=0.1cm, above right=0.1cm and 0.1cm of sensors.south west](acc){Accelerometer};
\node[block, fill=white, minimum width=\widthof{acc}, above right=0.1cm and 0.1cm of acc.north west](gyro){Gyroscope};
\node[block, fill=white, minimum width=\widthof{acc}, above right=0.1cm and 0.1cm of gyro.north west](mag){Magnetometer};
\end{tikzpicture}
\end{document}

In my code, I wish the acc block to be the reference block.

34

Acc is a node name it doesn't refer to the contents of the node (Acc) and \widthof{acc} means, measure the box that holds the text acc. So that's not gonna fly.

But it will if you record your longest text, say, Magnetometer then you supply that or the width you want (with inner sep correction) and use it in your style

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
\begin{document}
\begin{tikzpicture}[
block/.style={
draw,
fill=white,
rectangle, 
minimum width={width("Magnetometer")+2pt},
font=\small}]
\node[block](acc){Accelerometer};
\node[block,above=0.1cm of acc](gyro){Gyroscope};
\node[block,above=0.1cm of gyro](mag){Magnetometer};
\end{tikzpicture}
\end{document}

enter image description here

This has been demonstrated in many questions on this site and I don't really understand why minimum width is not making you happy but it is possible as demonstrated above. So these two are the most basic ones. You can also go fancier and measure some node and apply that to others that come after it but I don't see any difficulty in changing the text once.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
\begin{document}
\begin{tikzpicture}[
block/.style={
draw,
fill=white,
rectangle, 
text width={width("Magnetometer")},
align=center,
font=\small}]
\node[block](acc){Accelerometer};
\node[block,above=0.1cm of acc](gyro){Gyroscope};
\node[block,above=0.1cm of gyro](mag){Magnetometer};
\end{tikzpicture}
\end{document}

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.