# Tikz-cd and commutative diagrams

Hello everyone :) Tikz is new for me so I'm asking you this question. I use Tikz-cd to write an arithmetic sequence. So far so good. I want to put this in a minipage and there's where the problem comes:

If I compile this out of a minipage:

\begin{center}
\begin{tikzcd}
x_{1} \arrow[r,red,bend left,"+r"] & x_{2} \arrow[r,red,bend left,"+r"] &
x_{3} \arrow[r,red,bend left,"+r"] & x_{4} \arrow[r,red,bend left,"+r"] &
x_{5} \arrow[r,red,bend left,"+r",end anchor={[yshift=0.225cm]north}] &
\ldots
\end{tikzcd}
\end{center}


It gives no problems. But If I put this in an minipage environnement like

\fbox{\begin{minipage}{\textwidth}
\underline{\textbf{Définition}}:\newline\newline

Une suite \textbf{arithmétique} est

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$\newline

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$ \newline

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$ \newline

\begin{center}
\begin{tikzcd}
x_{1} \arrow[r,red,bend left,"+r"] & x_{2} \arrow[r,red,bend left,"+r"] & x_{3}
\arrow[r,red,bend left,"+r"] & x_{4} \arrow[r,red,bend left,"+r"] & x_{5}
\arrow[r,red,bend left,"+r",end anchor={[yshift=0.225cm]north}] & \ldots
\end{tikzcd}
\end{center}

\end{minipage}}\newline\newline


It gives the same 15 compilation erros "Undefined control sequence blablablabla l.... \end{minipage}\newline\newline". It's weird for me. Is there somebody that can explain the problem to me please :) ? Is there a possibility to put the diagram in the minipage like I would like to ? :) In advance Thx Everybody.

• (1) welcome, (2) as always on this site please post a full minimal example instead of sniplets, that makes it a lot easier to help you Commented Oct 8, 2017 at 9:43
• The issue is with \fbox, not minipage. Welcome to TeX.SE!
– Troy
Commented Oct 8, 2017 at 9:54

For technical reasons, when a TikZ matrix (and a tikzcd is such an object) is absorbed as the argument to another command, the ampersand replacement option must be enforced.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}

\usepackage{amsmath}
\usepackage{tikz-cd}

\begin{document}

\noindent
\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule}
\textbf{Définition}

\bigskip

Une suite \textbf{arithmétique} est
$\begin{tikzcd}[ampersand replacement=\&] x_{1} \arrow[r,red,bend left,"+r"] \& x_{2} \arrow[r,red,bend left,"+r"] \& x_{3} \arrow[r,red,bend left,"+r"] \& x_{4} \arrow[r,red,bend left,"+r"] \& x_{5} \arrow[r,red,bend left,"+r",end anchor={[yshift=1ex]north}] \& \dots \end{tikzcd}$
\end{minipage}}

\end{document}


A simple solution consists in using the framed environment, which has the advantage to break across pages.

However, while I'm at it, it would be simpler to define an unnumbered theorem environment in the break style, since the ntheorem package has a [framed] option.

In the code below I show both solutions. Finally, I advise against underlining theorem titles. Typographically speaking, this is very bad practice, which dates back to the ancient times of type writers, when it was not easy to change fonts and use italic or boldface.

\documentclass[french, svgnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usepackage{framed}

\usepackage[amsmath, thmmarks, framed]{ntheorem}

\colorlet{framecolor}{Tomato}
\theoremstyle{nonumberbreak}
\theorembodyfont{\normalfont}
\theoremseparator{:}
\theoreminframepreskip{0ex}
\theoreminframepostskip{0ex}
\theoremprework{\setlength{\fboxrule}{0.8pt}\let\oldfbox\fbox\def\fbox#1{\color{framecolor}\oldfbox{\color{black}#1}}}
\newframedtheorem{defi}{Définition}

\begin{document}

\begin{framed}\parindent = 0em
\underline{\textbf{Définition}}:

Une suite \textbf{arithmétique} est

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$

$\dotfill$

\begin{center}
\begin{tikzcd}
x_{1} \arrow[r,red,bend left,"+r"] & x_{2} \arrow[r,red,bend left,"+r"] & x_{3}
\arrow[r,red,bend left,"+r"] & x_{4} \arrow[r,red,bend left,"+r"] & x_{5}
\arrow[r,red,bend left,"+r",end anchor={[yshift=0.225cm]north}] & \ldots
\end{tikzcd}
\end{center}

\end{framed}%

\begin{defi}
Une suite \textbf{arithmétique} est

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$

$\ldots\ldots\ldots\ldots\ldots\ldots\ldots\ldots$

$\dotfill$

\begin{center}
\begin{tikzcd}
x_{1} \arrow[r,red,bend left,"+r"] & x_{2} \arrow[r,red,bend left,"+r"] & x_{3}
\arrow[r,red,bend left,"+r"] & x_{4} \arrow[r,red,bend left,"+r"] & x_{5}
\arrow[r,red,bend left,"+r",end anchor={[yshift=0.225cm]north}] & \ldots
\end{tikzcd}
\end{center}
\end{defi}

\end{document}


• Thx a lot everybody for the explanation ! Commented Oct 22, 2017 at 13:27