3

Having never worked with tkiz before, I can't even begin to understand how to draw this simple thing.

5 squares on a row, roman numbered 1 -> 5

I hate to beg for a "can someone make this for me" but after trying to make this solution work for me by fiddling, tweaking, reading and fumbling for hours on end, and not getting anywhere closer to a solution, I have to turn to my internetfriends for help...

So: basically I need the above drawing, lined out to the middle of the page...

Thank you for your help!

6

LaTeX allows you do use \Roman{<counter>} that automatically inserts the right roman number.

\documentclass[tikz,border=3.14mm]{standalone}
\newcounter{pft}
\begin{document}
\begin{tikzpicture}
 \foreach  \X in {1,...,5}
 {\node[minimum width=6mm] (\X) at (\X,0) {\setcounter{pft}{\X}\Roman{pft}};
 \draw(\X.north west) rectangle ([yshift=-3mm]\X.south east);}
 \draw([xshift=-1em]1.south west) -- ++ (0,2.5em) -| ([xshift=1em]5.south east);
\end{tikzpicture}
\end{document}

enter image description here

Or using text depth from Joule V's answer and Martin Scharrer's answer without counter and even more automatic.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
 \foreach  \X in {1,...,5}
 {\node[minimum width=8mm,text depth=2ex,draw] (\X) at (1.2*\X,0)
 {\uppercase\expandafter{\romannumeral\X\relax}};}
 \draw([xshift=-1em]1.west) -- ++ (0,2.5em) -| ([xshift=1em]5.east);
\end{tikzpicture}
\end{document}

enter image description here

  • I have no idea what I just copy/pasted but it works. Could you kind of explain what you and @JouleV did? I understand the foreach, but what is `\node and how do you get the |----| around it? – LooselySubtle May 18 at 19:36
  • @LooselySubtle \node is a TikZ command that, well, defines a node. This node has a main argument, its content, which is often a text (but can also be a graphics etc.). And these nodes have anchors, which we are using when we draw the hat over them. TikZ has a lot of functions, but the good news is that the pgfmanual has a nice tutorial, and this site many examples from which one can learn. – marmot May 18 at 19:40
  • 1
    @LooselySubtle, the TikZ manual can be a bit scary for its size, but I think you should at least read the first tutorial. It has been my starting point and it's so well written you can't not understand it (double negative on purpose). – Rmano May 18 at 19:49
6
\documentclass[tikz]{standalone}
\tikzset{mynode/.style={draw,minimum size=1.5cm,text depth=2\baselineskip}}
\begin{document}
\begin{tikzpicture}
\foreach \i/\ins in {1/I,2/II,3/III,4/IV,5/V} 
    \node[mynode] (\i) at (2*\i,0) {\ins};
\draw ([xshift=-.5cm]1.west) |- ([shift={(.5cm,.5cm)}]5.north east) -- ++ (0,-1);
\end{tikzpicture}
\end{document}

enter image description here

2

With employing of TikZ libraries chains and positioning:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, positioning}

\begin{document}
\begin{tikzpicture}[
node distance = 4mm,
  start chain = A going right,
   box/.style = {draw, minimum size=1.5cm,
                 label={[anchor=north,font=\large]:#1},
                 on chain=A}
                    ]
\foreach \i in {I, II, III, IV, V}
    \node[box=\i] {};
\draw ([xshift=-5mm] A-1.west) |- ([yshift=5mm] A-1.north) -| ([xshift=5mm] A-5.east);
\end{tikzpicture}
\end{document}

enter image description here

and with use of Stefan Kottwitz answer on for Roman numerals, which enable to draw arbitrary long chain of nodes:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, positioning}
\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

\begin{document}
\begin{tikzpicture}[
node distance = 4mm,
  start chain = A going right,
   box/.style = {draw, minimum size=1.5cm,
                     label={[anchor=north,font=\large]:\rom{#1}}, % <---
                     on chain=A}
                    ]
\def\Nmax{5}                    % <---
\foreach \i in {1,...,\Nmax}    % <---
    \node[box=\i] {};
\draw   ([xshift=-5mm] A-1.west) |- 
        ([yshift=5mm] A-1.north) -| ([xshift=5mm] A-\Nmax.east); % <---
\end{tikzpicture}
\end{document}

Result is the same as before.

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.