# How can I make a nicely aligned diagram like this in LaTeX?

It is a pretty simple diagram, basically the result I'm trying to get is something like this: Where the three equations are aligned to the left. I've tried using TikZ and Tikz-cd, but this is the best I can get to (I use the hphantoms so the arrow is more to the left):

\begin{center}
\begin{tikzcd}[row sep = tiny, column sep = -1 em]
\hphantom{a} \arrow[dd, leftrightarrow, bend right = 60] & x = \sin{t} \\
\hphantom{aa} & \dfrac{dx}{dt} = \cos{t} \\
\hphantom{aaa} & \dfrac{d^2x}{dt^2} = -\sin{t}
\end{tikzcd}
\end{center}


Which produces So neither the arrow nor the equations are aligned (however, aligning the equations is the important thing).

How could I make this better? Ty in advance.

• I think using a normal amsmath environment like align and tikzmark is the way to go. Sep 17 at 13:39

You could do this with tikz-cd. Just use one column and set text width=0mm. But I would suggest that this would look better if the = signs were aligned. As @Qrrbrbirlbel commented, the align* environment together with tikzmark is the way to go.

Note also, that if you have additional columns, the textwidth=0 trick will fail. Instead use text width=2cm (or whatever you choose) and add start anchor=west, end anchor=west to the arrow. \documentclass{article}

\usepackage{tikz-cd, amsmath}

\begin{document}
\begin{center}
\begin{tikzcd}[row sep = tiny, text width=0mm]
x = \sin{t}\arrow[dd, leftrightarrow, bend right = 60] \\
\dfrac{dx}{dt} = \cos{t} \\
\dfrac{d^2x}{dt^2} = -\sin{t}
\end{tikzcd}
\end{center}
\end{document}

• This is perfect! I also looked up tikzmark (which I didn't know anything about) as @Qrrbrbirlbel suggested and managed to do it, so now I have both an answer using tikz-cd and in a more suitable/correct package. Thank you both! Sep 17 at 14:41

In both the following solutions, you'll see the value .3333em, this is the default inner xsep for nodes in TikZ.

Since we don't even have a node with the TikZmark solution we'll add that in manually. The TikZ-CD solution uses inner xsep=0pt to tightly pack the nodes together but uses outer xsep=.3333em so that the anchorborder lies where it usually would again.

## TikZmark

This allows the full control of amsmath (e.g. equation numbering).
The \tml (l for left) macro is a wrapper for \tikzmark that adds a horizontal space and shifts the mark by .5ex so that it lies in the middle of the line (and not at its baseline).

### Code

\documentclass[varwidth]{standalone}
\usepackage{tikz,amsmath}
\usepackage{esdiff}
\usetikzlibrary{tikzmark,arrows.meta}
\tikzset{tm/.style={overlay, remember picture}}
\newcommand*\tml[]{%
\llap{\tikzmark[#1]{#2,baseline=-.5ex}\hspace{.3333em}}}
\begin{document}
\begin{align}
\tml{a} x & = \sin t  \\
\diff x t & = \cos t  \\
\tml{b} \diff x t & = -\sin t
\end{align}
\tikz[tm] \draw[Latex-Latex]
(pic cs:b) to[bend left=60] ({pic cs:a}-|{pic cs:b});
\end{document}


### Output ## TikZ-CD

With TikZ-CD you won't get any equation numbering (though we could just put that all in a equation environment to get at least one number).

Notice the {} in front of the = in the second column. This makes sure the spacing around the = is right. (AMSmath's environments insert that automatically.)

### Code

\documentclass[varwidth]{standalone}
\usepackage{tikz-cd}
\usepackage{esdiff}
\usetikzlibrary{ext.node-families}% https://ctan.org/pkg/tikz-ext
\tikzcdset{
left connect/.style={
bend right=60, Latex-Latex, start anchor=west, end anchor=west},
align col/.style 2 args={
/tikz/column #1/.append style={
node family={
text width=\tikzmatrixname-\the\pgfmatrixcurrentcolumn,
text width align=#2}}}}
\begin{document}
\begin{center}
\begin{tikzcd}[
row sep=0pt, column sep=0pt, nodes={inner xsep=0pt, outer xsep=.3333em},
align col=1right, align col=2left,
]
x \ar[dd, left connect] & {} = \sin t \\
\diff x t & {} = \cos t \\
\diff x t & {} = -\sin t
\end{tikzcd}
\end{center}
\end{document}


### Output • I've also used esdiff like the others. Seems like a small but helpful package in writing derivatives. Sep 17 at 16:34

A simple solution with pstricks: I insert empty nodes at the beginning of the first and third lines of an align* environment and connect them with an arc connection:

    \documentclass{article}

\usepackage{amsmath}
\usepackage{esdiff}
\usepackage{pst-node}

\begin{document}

\begin{align*}
\pnode[0, 0.5ex]{A}\hspace{1.7em} x & = \sin t \\
\diff x t & = \cos t \\
\pnode[0, 0.5ex]{B}\enspace \diff x t & = -\sin t
\psset{arrowinset=0}
\ncarc[arcangle=40]{<->}{B}{A}
\end{align*}

\end{document} A bit less simple (short) solution with use of the \tikzmarknode defined in TikZ library tikzmark, as suggested by @Qrrbrbirlbel in his comment:

\documentclass{article}
\usepackage{tikz}           % <---
\usetikzlibrary{arrows.meta,
tikzmark}   % <---
\tikzset{>=Straight Barb,
is/.style = {inner xsep=3pt}
}

\usepackage{amsmath}
\usepackage{esdiff}

\begin{document}

\begin{align*}
\tikzmarknode[is]{a}{x} & = \sin t \\
\diff x t   & = \cos t \\
\tikzmarknode[is]{b}{\diff x t} & = -\sin t
\end{align*}
\begin{tikzpicture}[overlay, remember picture]
\draw [red, very thick, <->] (a.south -| b.west) to[bend right=45] (b.west);
\end{tikzpicture}
\end{document}


For final result you need to compile MWE three times. A shorter PSTricks example. Run with lualatex

\documentclass{article}
\usepackage{amsmath}
\usepackage{esdiff}
\usepackage{pst-node}
\begin{document}

\begin{align*}
\rnode{A}{\phantom{d^2}x} &= \sin t \\
\diff x t & = \cos t \\
\rnode{B}{\diff x t} & = -\sin t
\nccurve[arrowinset=0,angle=180]{<->}{B}{A}
\end{align*}

\end{document} 