TransWikia.com

TikZ-cd Diagrams Side-by-Side

TeX - LaTeX Asked on February 17, 2021

I have two diagrams – drawn in TikZ-cd – which I’d like to have side-by-side. However, even though I haven’t left a blank line between the code for the two diagrams, they still appear above/below one another.

Here’s a MWE:

documentclass[12pt]{article}

usepackage[margin=20mm]{geometry} %changes margins
usepackage{mathrsfs} % fancy maths latters
usepackage{amsmath} %improves equation environment

usepackage{tikz-cd} %diagrams

usepackage{subcaption} %side by side diagrams
usepackage{caption} %customises captions



title{Side-by-Side Diagrams MWE}

begin{document}

maketitle

Here are two diagrams that I would like to have side-by-side:

begin{figure}[h!]
    centering
    begin{tikzcd}[column sep=small]
    mathscr{L}_{1} &  & mathscr{L}_{2}
    & p_{1} arrow[lu] arrow[ru] &
    & text{Argument} arrow[u] &
    end{tikzcd} caption{Many-one pluralism.}
    begin{tikzcd}[column sep=small]
    mathscr{L}_{1} &  & mathscr{L}_{2}
    p_{1} arrow[u] &  & p_{2} arrow[u]
    & text{Argument} arrow[lu] arrow[ru] &
    end{tikzcd} caption{One-many pluralism.}
end{figure}

end{document}

Which outputs:

enter image description here

I’ve also tried using mini-pages, sub-floats (e.g. Two diagrams side by side), and the subcaption package (e.g. Placing TikZ drawings in a minipage side by side) to solve the problem, but in each case I get loads of errors… (Maybe these packages are compatible with TikZ but not TikZ-cd?) Thanks for your help!

One Answer

You can have it with floatrow, if you enable the replacement of & with &:

documentclass[12pt]{article}

usepackage[margin=20mm]{geometry} %changes margins
usepackage{mathrsfs} % fancy maths latters
usepackage{amsmath} %improves equation environment
usepackage{tikz-cd} %diagrams

usepackage{subcaption} %side by side diagrams
usepackage{caption} %customises captions
usepackage{floatrow}
title{Side-by-Side Diagrams MWE}
author{I. Ego}
begin{document}

maketitle

Here are two diagrams that I would like to have side-by-side:

begin{figure}[h!]
    tikzset{column sep=small, ampersand replacement=&}
begin{floatrow}
    centering
    ffigbox{begin{tikzcd}
    mathscr{L}_{1} & & mathscr{L}_{2}
    & p_{1} arrow[lu] arrow[ru] &
    & text{Argument} arrow[u] &
    end{tikzcd}}{caption{Many-one pluralism.}}
    ffigbox{begin{tikzcd}
    mathscr{L}_{1}& & mathscr{L}_{2}
    p_{1} arrow[u] & & p_{2} arrow[u]
    & text{Argument} arrow[lu] arrow[ru] &
    end{tikzcd}}{caption{One-many pluralism.}}
    end{floatrow}
end{figure}

end{document}

enter image description here

Correct answer by Bernard on February 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP