3

Consider:

Figure 1

Figure 2

I know that the short answer is 'use TikZ'. However, TikZ is extremely powerful and I would use it when I needed complicated graphs. But I believe there are other better options for such a short task like below. That's why I'm asking.

For example, we can simply use \boxed{} inside an equation to box that equation using amsmath. Likewise, I just want to box some texts and put some arrows among them. Is there an alternative to TikZ for this small task? If not, can you give any clue on how to draw any one of the particular figures below?

And worst case scenario, let's say there is no alternative to TikZ for this purpose. Then I tried the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}
\draw (0,0) -- (4,0) -- (4,1) -- (0,1) -- cycle node(b1) {Box 1};
\draw (8,0) -- (12,0) -- (12,1) -- (8,1) -- cycle node(b2) {Box 2};
\draw [arrow] (b1) -- (b2);
\end{tikzpicture}

\end{document}

But it doesn't give the output I intended. For example, I cannot put the text inside the rectangle. Also, how to fix the arrow position? How to write text in the middle of an arrow? This code gives me the following picture:

Enter image description here

PS: These example images are extracted from Jakob Schwichtenberg's "No-nonsense Classical Mechanics" book.

5
  • Try with tikzcd package. Text in nodes and labels I would write in two lines, By this diagram will become more readable.
    – Zarko
    Jun 12, 2022 at 8:34
  • 1
    It should be as impler code with pstricks and the psmatrix environment of pst-node.
    – Bernard
    Jun 12, 2022 at 8:34
  • 1
    Suggestions: place and \draw \nodes first. Look up and try a little: \node, [in=, out=], also \graph, include the tikzlibraries as indicated in the manual, like arrows.meta. It's less complicated, and powerful. Have a look at, learn and adapt from here: texample.net/tikz/examples/feature/node-positioning .
    – MS-SPO
    Jun 12, 2022 at 8:34
  • 1
    Also kindly have a look and my Q&A on this subject, which was enriched by David's inspiring comment: tex.stackexchange.com/questions/647400/… . Just replace "image" in said examples with "text" and you will be hard to stop.
    – MS-SPO
    Jun 12, 2022 at 8:40
  • 1
    Hi @MS-SPO, I posted an answer based on your last comment. But there is still an issue. Could you look at my answer, please? This is not a big issue but I'd love to know how to fix this. Jun 12, 2022 at 9:01

5 Answers 5

8

Here is a solution for both diagrams using tikz-cd. Using the option cells={nodes={draw}} will draw the box around each cell.

enter image description here

enter image description here

\documentclass{article}

\usepackage{tikz-cd}
\tikzset{smalltext/.style={"\textup{\small #1}" description}}

\begin{document}

\[\begin{tikzcd}[cells={nodes={draw}}, row sep=2cm, column sep=3cm]
\textup{equation of motion}
    \arrow[r, smalltext=describes] 
    \arrow[d, smalltext=initial condtions]
    & \textup{system abstractly}\\
\textup{solution}\arrow[r, smalltext=describes] & \textup{evolution of concrete preparation of system}
\end{tikzcd}\]

\vspace{2cm}

\[\begin{tikzcd}[cells={nodes={draw}}, row sep=2cm, column sep=2cm]
    & \textup{Equation of Motion} \\
    & \textup{Newtonian Mechanics}\arrow[u, smalltext=Newton's Second Law] \\
\textup{Hamiltonian Mechanics}\arrow[uur, bend left, smalltext=Hamilton's Equations]
    & \textup{Classical Mechanics} \arrow[u, smalltext=Physical Space]\arrow[l, bend right=20, smalltext=Phase Space]\arrow[r, bend left=20, smalltext=Configuration Space]
    & \textup{Lagrangian Mechanics}\arrow[uul, bend right, smalltext=Euler-Lagrange Equation]\arrow[ll,<->,bend left, smalltext=Legendre Transform]
\end{tikzcd}\]

\end{document}
4

A little bit more advanced solution with redesigned texts' boxes, were I would write content in two lines. By this diagram become (to my opinion) more compact and easier to read. For all image elements are defined common styles. I'm sorry, but it is not clear to me, how should be oriented text at vertical arrows. Now I guess that it be sloped along arrow:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 22mm and 33mm,
    box/.style = {draw, minimum size=3em, align=center},
every edge/.style = {draw, -Straight Barb},
every edge quotes/.append style = {font=\small, fill=white, 
                                   anchor=center, align=center, sloped},
                        ]
\scoped[nodes=box]
{
\node (eqm)                 {Equation\\ of Motion};
\node (sa)  [right=of eqm]  {System\\ Abstractly};
\node (sol) [below=of eqm]  {Solution};
\node (ev)  [below=of sa]   {Evolution of Concrete\\ 
                             Preparation of System};
}
%%%%
\path   (eqm) edge ["Initial\\ Condition"]    (sol) 
        (eqm) edge ["Describes"]            (sa)
        (sol) edge ["Describes"]            (ev);
    \end{tikzpicture}
\end{document}

enter image description here

Edit: If you not liked to have edges' text aligned along arrow, than just remove option sloped from every edge quotes style:

every edge quotes/.append style = {font=\small, fill=white, 
                                   anchor=center, align=center},

Then the result of compilation become:

enter image description here

3

(Well done!) Not sure, if I get you right, but here are two variants (but see below). Your choices are well decribed in the big pgf manual, which progresses from coarse to fine details from chapter to chapter (so it's good to read and follow, even when it's so overwhelmingly huge).

enter image description here

\documentclass[10pt, border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}

\begin{document}

\tikz {
    
    \node (eqm) [draw] at (0,0)     {Equation of Motion};
    \node (sa) [draw] at (10,0)     {System Abstractly};
    \node (sol) [draw] at (0, -4)    {Solution};
    \node (ev) [draw] at (10, -4)    {Evolution of Concrete Preparation of System};
    
    \draw [->] (eqm) -- node [left] {\small{Initial Condition}} (sol);% <<<
    \draw [->] (eqm) -- node [sloped] {\small{Describes }} (sa);% <<<
    \draw [->] (sol) -- node [sloped, above] {\small{Describes }} (ev);

    }

\end{document}

You probably want this, possibly removing the sloped option, too: enter image description here

\draw [->] (eqm) -- node [sloped, fill=white] {\small{Describes }} (sa);% <<<
3

Is this what you need? I changed the "Initial Condition" to what you wanted in your original question. If you don't like it, just use the [rotate=-90] one. Hope it helps.

\documentclass[10pt, border=3mm]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{graphs}
    \begin{document}
    \tikz {
        \node (eqm) [draw] at (0,0){Equation of Motion};
        \node (describe1) [] at (5,0){\footnotesize Describes};
        \node (sa) [draw] at (10,0){System Abstractly};
        %\node (ini_cond) [rotate=-90] at (0,-2){\footnotesize Initial Condition}; if you still need the [rotate=-90].
        \node (ini_cond) [] at (0,-2){\footnotesize Initial Condition};
        \node (sol) [draw] at (0, -4){Solution};
        \node (describe2) [] at (3.5,-4){\footnotesize Describes};
        \node (ev) [draw] at (10, -4){Evolution of Concrete Preparation of System};
        \draw [->] (eqm) --(ini_cond)--(sol);
        \draw [->] (eqm)--(describe1)--(sa);
        \draw [->] (sol) --(describe2)--(ev);
        }
    \end{document}

enter image description here

1

Thanks to @MS-SPO's comment, I am posting an answer to my own question. However, there is a little small detail that I still cannot figure out. That is if it's possible to put the text in the middle of the arrow instead of above the arrow. I now get the following diagram by using the following code.

enter image description here

\documentclass[10pt, border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}

\begin{document}

\tikz {
    
    \node (eqm) [draw] at (0,0)     {Equation of Motion};
    \node (sa) [draw] at (10,0)     {System Abstractly};
    \node (sol) [draw] at (0, -4)    {Solution};
    \node (ev) [draw] at (10, -4)    {Evolution of Concrete Preparation of System};
    
    \draw [->] (eqm) -- node [sloped, above] {\small{Initial Condition}} (sol);
    \draw [->] (eqm) -- node [sloped, above] {\small{Describes }} (sa);
    \draw [->] (sol) -- node [sloped, above] {\small{Describes }} (ev);

    }

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .