1

I want to have following example format for two tikz figures, where (a) and (b) are located at most left side of them.

Example reference: Cormen/Introduction to Algorithms 2022 page: 341

enter image description here

Please note that I am only interested for placing (a), (b), (c), ... labels.


The solution I come up with is using How to label/tag TikZ diagrams?. But here I was not able to change equation numbers (2) to (a) and (3) to (b) , also I was not able to change their location to the most left hand side.

my tex code:

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{blindtext}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\setcounter{page}{15}
\noindent

\begin{equation} \begin{tikzcd} x = 5 * 5; \ \end{tikzcd} \end{equation} into a commutative diagramm \begin{equation} \begin{tikzcd} B\times_A C \arrow{r}{\pi_2}\arrow{d}[swap]{\pi_1} & C\arrow{d}{g} \ B \arrow{r}[swap]{f} & A; \end{tikzcd} \end{equation}

\begin{equation} \begin{tikzpicture}[compute/.style={draw,thick,font=\sffamily, append after command={ (\tikzlastnode.south west) edge[double=gray!50,double distance=3pt, line cap=rect, shorten >=-2pt,shorten <=-2pt] (\tikzlastnode.south east)}}] \node[compute] (n1) {Node}; \node[compute,right=2cm of n1] (n2) {More text}; \draw[thick,-stealth] (n1) -- (n2); \end{tikzpicture} \end{equation} \end{document}

output:

enter image description here

wanted output:

enter image description here

alper
  • 1,389
  • As I see it this isn't a [tag:tikz-pgf] problem but one about numbering equations? (Unless the numbering should be part of the TikZ picture?) What should happen after (z)? – Qrrbrbirlbel Oct 09 '22 at 20:11
  • @Qrrbrbirlbel I added numbering, should I remove tikz-pgf ? I never thought about what will happen after z , at most I thought I will use till g – alper Oct 09 '22 at 21:18

1 Answers1

2

I'm guessing that you like to obtain the following:

enter image description here

Using @Andrew Swann answer you can write:

\documentclass{article}
\usepackage{lipsum}

\usepackage{amsmath} \makeatletter \newcommand{\leqnos}{\tagsleft@true\let\veqno@@leqno} \newcommand{\reqnos}{\tagsleft@false\let\veqno@@eqno} \reqnos \makeatother \newcounter{eqtn}

\usepackage{tikz-cd} \usetikzlibrary{positioning}

\begin{document} \setcounter{page}{15}

\begin{equation} a^2 + b^2 = c^2 \end{equation} \lipsum[3][1-3]

\begingroup\leqnos \setcounter{eqtn}{\theequation} \setcounter{equation}{0} \renewcommand\theequation{\alph{equation}} \begin{equation} \begin{tikzcd} x = 5 * 5; \ \end{tikzcd} \end{equation} into a commutative diagramm \begin{equation} \begin{tikzcd} B\times_A C \arrow{r}{\pi_2}\arrow{d}[swap]{\pi_1} & C\arrow{d}{g} \ B \arrow{r}[swap]{f} & A; \end{tikzcd} \end{equation}

\begin{equation} \begin{tikzpicture}[compute/.style={draw,thick,font=\sffamily, append after command={ (\tikzlastnode.south west) edge[double=gray!50,double distance=3pt, line cap=rect, shorten >=-2pt,shorten <=-2pt] (\tikzlastnode.south east)}}] \node[compute] (n1) {Node}; \node[compute,right=2cm of n1] (n2) {More text}; \draw[thick,-stealth] (n1) -- (n2); \end{tikzpicture} \end{equation} \setcounter{equation}{\theeqtn} \endgroup \lipsum[66] \begin{equation} a^2 + b^2 = c^2 \end{equation}

\end{document}

I wonder, why you not use the sidcap package and use for example as

\begin{SCfigure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}

and for them change caption numbering on the similar way as is done above.

Edit: Simpler code with manual tagging of equation:

\documentclass{article}
\usepackage{lipsum}

\usepackage{amsmath} \makeatletter \newcommand{\leqnos}{\tagsleft@true\let\veqno@@leqno} \newcommand{\reqnos}{\tagsleft@false\let\veqno@@eqno} \reqnos \makeatother

\usepackage{tikz-cd} \usetikzlibrary{positioning}

\begin{document} \setcounter{page}{15}

\begin{equation} a^2 + b^2 = c^2 \end{equation} \lipsum[1][1-3]

\begingroup\leqnos \begin{equation} \begin{tikzcd} x = 5 * 5; \tag{a}\ \end{tikzcd} \end{equation} into a commutative diagramm \begin{equation} \begin{tikzcd} B\times_A C \arrow{r}{\pi_2}\arrow{d}[swap]{\pi_1} & C\arrow{d}{g} \ B \arrow{r}[swap]{f} & A; \end{tikzcd} \tag{b} \end{equation}

\begin{equation} \begin{tikzpicture}[compute/.style={draw,thick,font=\sffamily, append after command={ (\tikzlastnode.south west) edge[double=gray!50,double distance=3pt, line cap=rect, shorten >=-2pt,shorten <=-2pt] (\tikzlastnode.south east)}}] \node[compute] (n1) {Node}; \node[compute,right=2cm of n1] (n2) {More text}; \draw[thick,-stealth] (n1) -- (n2); \end{tikzpicture} \tag{a} \end{equation} \endgroup \lipsum[66] \begin{equation} a^2 + b^2 = c^2 \end{equation}

\end{document}

Compilation result is the same as before.

Zarko
  • 296,517
  • Mostly yes, just after the into a commutative diagramm line can it start with (a) again? – alper Oct 09 '22 at 21:16
  • Try to reset equationnumber. Or even simpler, in equation insert numbers manually. I will show this ASAP. – Zarko Oct 09 '22 at 21:19
  • I had not idea sidcap existed , if it provides simplier solution I can switch to using that, since in some other cases may end up using (a) (b) bottom of the tikz-image – alper Oct 09 '22 at 21:20
  • Is it possible to show tag leftmost middle , like here instead it shows up at bottom leftmost : https://gist.github.com/avatar-lavventura/87c3799313d5de5a8a44473d2e429c3f?permalink_comment_id=4329524#gistcomment-4329524 – alper Oct 09 '22 at 22:58
  • 1
    @alper, yes it is possible. Just add to tikzpicture option baseline=(current bounding box.center),. – Zarko Oct 09 '22 at 23:46
  • Inside the \begin{equation}...\end{equation} we also align tikzfigure to rightmost instead of keeping it centered? – alper Oct 10 '22 at 00:08
  • @alper, sorry, I don't understand your comment. If you have new problem, please ask new question, where with an MWE show your problem. – Zarko Oct 10 '22 at 00:12
  • @alper, sory, this site is not a forum bit question/answer site. Please (again) ask new question qith your new problem. – Zarko Oct 10 '22 at 00:23
  • / okay sorry ... – alper Oct 10 '22 at 00:27