1

I have two Tikz diagrams - let's denote their code by $D$ and $D'$. Now I want to display them in a row, so I put them in align. That is I write

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{align} D & & D' \end{align*}

\end{document}

In addition I would like to put a caption under each diagram. I tried to use the caption software, but doesn't seem to work in the align environment. How can I fix this?

Zarko
  • 296,517
  • 4
    Why do you want to use the align environment? Are your TikZ diagrams actually equations? If not just write them without a blank line (→ new paragraph) between them. Horizontal alignment can be adjusted with the center environment or the \centering command inside a figure environment, the minipage environment (or even with TikZ itself). The subcaption package or related ones can help with adding captions to each diagram. There are many Qs about this on this site. – Qrrbrbirlbel Apr 24 '23 at 17:03
  • @Qrrbrbirel: Thanks for the all the suggestions. Unfortunately I am getting a bit confused. Could you write out a short example? Or direct me to some of the Q&As on the site. – Jean Robert Apr 24 '23 at 17:50
  • https://tex.stackexchange.com/q/5769/1952. Replace the \includegraphics by your TiKZ figures and you will get it. – Ignasi Apr 24 '23 at 18:20

2 Answers2

0

Here's a way to do it, adopting the comments, mainly from Ignasi:

result

Kindly check the package documentation from subfigure at ctan for details.

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}       % for Tikz
\usepackage{lipsum}     % some blindtext
\usepackage{subfigure}  % assuming both figures belong together somehow

\begin{document} \lipsum[10] See figure \ref{fig}.

\begin{figure}[!h]
    \centering
    \subfigure[Left demo]{% "split", just to show the structure
        \tikz{% <<< put those % to avoid insertion of unwanted spaces, i.e. shifts
            \draw (0,0) rectangle (3,2);%
        }%
    }
    \hspace{2cm}% some extra horizontal separation
    \subfigure[Right demo]{\tikz{\draw[fill=green!20] (0,0) rectangle (2,3);}}
\caption{Two demo figures with Tikz}\label{fig}
\end{figure}

\lipsum[11]

\end{document}

MS-SPO
  • 11,519
0

Your question is not clear about how you like to present your figures. With captions or without it? As subfigures in figure or as two independent figures Or figure with two images? Hence MWE (Minimal Working Example) below contain all three listed scenarios:

\documentclass{article} % or some other suitable document class
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum}                             % for dummy text
%---------------------------------------------------------------%
\usepackage{subcaption} 
\usepackage{tikz}

\begin{document} \lipsum[66] \begin{figure}[ht] \centering \subfloat[Left demo \label{subfig:a}]{\tikz\node[draw] {left subfigure};} \hfil \subfloat[Right demo \label{subfig:b}]{\tikz\node[draw] {right subfigure};}

\caption{As two sub figures drawn with TikZ}
\label{fig} \end{figure}

As you can see in subfigure \ref{subfig:a} in figure \ref{fig} \dots

\begin{figure}[ht]
\centering

\begin{minipage}{0.45\linewidth}\centering \tikz\node[draw] {left figure}; \caption{Your left figure drawn by TikZ package} \label{fig:a} \end{minipage} \hfil \begin{minipage}{0.45\linewidth}\centering \tikz\node[draw] {right figure}; \caption{Your right figure drawn by TikZ package} \label{fig:b} \end{minipage} \end{figure} As you can see in figure \ref{fig:a} and figure \ref{fig:b} \dots

At the end also example, when sub figures haven't own captions: \begin{figure}[ht] \centering \tikz\node[draw, text width=0.4\linewidth] {left figure drawn using TikZ package}; \hfil \tikz\node[draw, text width=0.4\linewidth] {right figure drawn using TikZ package};

\caption{As two images in figure, drawn with TikZ} \label{fig:3} \end{figure} \end{document}

enter image description here

(red lines only shows text block area)

Zarko
  • 296,517