1

I would like to create a flowchart in LaTeX with this basic design:

enter image description here

I have tried following the Creating Flowcharts tutorial from Overleaf, but I couldn't find out how to add the titles to the boxes.

What I currently have is the following code:

\tikzstyle{box} = [rectangle, rounded corners, minimum width=5cm, minimum height=2cm,text centered, draw=black, fill=black!15]
\tikzstyle{arrow} = [very thick, ->, >=stealth]

\begin{tikzpicture}[node distance=4cm] \node (box1) [box] {text}; \node (box2) [box, below of=box1] {more text}; \draw [arrow] (box1) -- (box2); \end{tikzpicture}

This produces the following flowchart:

enter image description here

Now I would just like to add the titles to the boxes, as in the first image.

  • Welcome to TeX.SE! It would be helpful if you could edit into your question your current code and what it looks like, it is fine if it doesn't work or have what you want that's what this question is for, but questions like this that don't show you have wrote any code are not how this site works. Could you edit into your question some code that you have wrote please? – JamesT Jul 09 '23 at 22:25
  • 1
    @JamesT I just updated the question. – oakley09 Jul 09 '23 at 23:28
  • 1
    Define \tikzset{header/.style={label={[rectangle, fill=white, draw, anchor=center, name=\tikzlastnode-header]north:{#1}}}} in the preamble and then \node (box2) [box, below of=box1, header=Title2] {more text}; \draw[arrow] (box1) -- (box2-header); for example. – Qrrbrbirlbel Jul 09 '23 at 23:34
  • Exactly what I was looking for, thank you @Qrrbrbirlbel ! – oakley09 Jul 09 '23 at 23:45
  • 2
    @Qrrbrbirlbel, please extend your comment to an answer, please. – Zarko Jul 10 '23 at 01:44
  • You can use tcolorbox package, similarly as is done in in the second addendum in the https://tex.stackexchange.com/a/690603/ – Zarko Jul 10 '23 at 01:46

1 Answers1

3

This seems like a job for a label which is just another node added afterwards which is placed in relation to the main node.

Depending on your usage, you might want to use something more automatic that automatically chooses whether <name> or <name>-header will be used for the arrows.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, positioning}
\tikzset{
  box/.style = {
    rectangle, rounded corners, minimum width=5cm, minimum height=2cm,
    text centered, draw=gray, fill=black!15},
  arrow/.style={very thick, -Stealth},
  header/.style={
    label={[rectangle, fill=white, draw, anchor=center,
            minimum width=2cm, node font=\ttfamily,
            name=\tikzlastnode-header]north:{#1}}}}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (box1) [box, header = Title1]                {text};
\node (box2) [box, header = Title2, below=of box1] {more text};
\draw [arrow] (box1) -- (box2-header);
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821