2

I am a newbie to latex and I am trying to compile notes. I came across an equation and I am wondering how it was produced. I haven't tried any method as I have no clue. Please help particularly with how to draw these lines.

Virtual work equation.

1 Answers1

3
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

    \[ 
    \tikzmarknode{N1}{1}\cdot
    \tikzmarknode{N2}{\Delta}=\Sigma
    \tikzmarknode{N3}{\vphantom{L}u}\cdot
    \tikzmarknode{N4}{dL}
    \]

    \begin{tikzpicture}[overlay,remember picture,shorten <=2pt]
        \draw (N1) |-++ (3,.5) node[right] {virtual loadings};
        \draw (N3) --++ (0,.5);

        \draw (N2) |-++ (3,-.5) node[right] {real displacements};
        \draw (N4) --++ (0,-.5);
    \end{tikzpicture}

\end{document}

simple tikzmark

Note that \vphantom{L} into node N3 is only here to avoid height disrupcy on your equation which would lead to mandatory manual setting for the drawing lines afterwards. With it, you don't have to think about it in the tikzpicture part.

EDIT

A more logical solution is to declare nodes for the legends and draw the second paths to the nodes. It avoids any \vphantom into the equation.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\[ 
\tikzmarknode{N1}{1}\cdot
\tikzmarknode{N2}{\Delta}=\Sigma
\tikzmarknode{N3}{u}\cdot
\tikzmarknode{N4}{dL}
\]

\begin{tikzpicture}[overlay,remember picture,shorten &lt;=2pt]

    \draw (N1) |-++ (3,.5) node[right] (V) {virtual loadings};
    \draw (N3) |- (V);

    \draw (N2) |-++ (3,-.5) node[right] (R) {real displacements};
    \draw (N4) |- (R);
\end{tikzpicture}

\end{document}

v2

SebGlav
  • 19,186
  • I just edited my post to add a second version to avoid \vphantom into the equation. – SebGlav Mar 11 '21 at 05:59
  • 2
    Thanks a million times – Richard Nkhoma Mar 11 '21 at 06:52
  • Hi, @SebGlav. I'd like to do something similar, although slightly different and I hope I can dot it learning from your code. Could you add a brief explanation about the functions of each part of your code? Thank you in advance. – Alice Sep 05 '23 at 14:24
  • 1
    @Alice I strongly recommend to read the tikzmark package documentation which is very self explanatory. Then, feel free to ask another question on TeX-SE, adding the tikz and tikzmark tags. You sure will get answers. Briefly, \tikzmarknode adds a node containing the text, which node you can use later to draw from, or whatever you want to do with it. Here I created nodes for 1, Delta, u and dL and drew lines from them. – SebGlav Sep 06 '23 at 09:49
  • 1
    Thank you so much. Eventually, I figured it out. – Alice Sep 14 '23 at 20:44