1

When loading tabularray (only in recent CTAN, I needed to manually copy it with ninecolors in my system) together with quantikz, tabularray just crashes as reported here https://github.com/lvjr/tabularray/issues/156

ERROR: Misplaced alignment tab character &.

MWE

\documentclass{memoir}
\usepackage{quantikz}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{center} \begin{tblr}{ rows = {35pt}, columns = {35pt}, rowsep = 1pt, colsep = 1pt, stretch = 0, cells = {c,font=\Huge}, cell{odd}{even} = {azure7}, cell{even}{odd} = {azure7}, hlines, vlines, } a & b & c & d & e & f & g & h \ a & b & c & d & e & f & g & h \ & & & & & & & \ & & & & & & & \ & & & & & & & \ & & & & & & & \ a & b & c & d & e & f & g & h \ \end{tblr} \end{center}

\end{document}

tobiasBora
  • 8,684

2 Answers2

1

Problem solved, thanks David Carlisle! (feel free to write your own answer if you want me to accept it)

\documentclass{memoir}
\usepackage{quantikz}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{center} \catcode`&=4 \begin{tblr}{ rows = {35pt}, columns = {35pt}, rowsep = 1pt, colsep = 1pt, stretch = 0, cells = {c,font=\Huge}, cell{odd}{even} = {azure7}, cell{even}{odd} = {azure7}, hlines, vlines, } a & b & c & d & e & f & g & h \ a & b & c & d & e & f & g & h \ & & & & & & & \ & & & & & & & \ & & & & & & & \ & & & & & & & \ a & b & c & d & e & f & g & h \ \end{tblr} \end{center}

\end{document}

tobiasBora
  • 8,684
  • Since you're inside center, the additional braces are not needed. The % after 4 is wrong. – egreg Nov 26 '21 at 17:12
  • Thanks for the comment. Wrong like useless, or wrong like harmful? I tend to protect all my code by grouping/commenting even if it may not be useful ^^ It can't harm right? – tobiasBora Nov 26 '21 at 17:15
  • Wrong like harmful. See https://tex.stackexchange.com/a/74541/4427 – egreg Nov 26 '21 at 17:17
1

The quantikz package makes the dubious decision to globally make & active and so conflicts with other packages that expect & to have its standard meaning are likely.

It does so in order to be able to internally call tikzcd as an argument to other commands (the quantikz environment, actually, which absorbs its contents through \NewEnviron), so as to avoid using ampersand replacement.

You can fix this behavior by absorbing the environment's content and change & to an active copy thereof. The standard category code of & is globally reinstated.

\documentclass{article}
\usepackage{quantikz}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

% fix the category code problem \catcode`&=4

% change the quantikz environment \ExplSyntaxOn\makeatletter

\RenewDocumentEnvironment{quantikz}{O{} +b} { \tl_set:Nn \l__quantikz_body_tl { \tikzcd@ [#1] #2 } \regex_replace_all:nnN { & } { \cA& } \l__quantikz_body_tl \tl_use:N \l__quantikz_body_tl \endtikzcd }{} \tl_new:N \l__quantikz_body_tl

\makeatother\ExplSyntaxOff

\begin{document}

\begin{quantikz} \lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \gate{U} & \ctrl{1} & \swap{2} & \ctrl{1} & \qw \ \lstick{$\ket{0}$} & \gate{H} & \targ{} & \octrl{-1} & \control{} & \qw & \octrl{1} & \qw \ &&&&&\targX{} & \gate{U} & \qw \end{quantikz}

\begin{tblr}{ rows = {35pt}, columns = {35pt}, rowsep = 1pt, colsep = 1pt, stretch = 0, cells = {c,font=\Huge}, cell{odd}{even} = {azure7}, cell{even}{odd} = {azure7}, hlines, vlines, } a & b & c & d & e & f & g & h \ a & b & c & d & e & f & g & h \ & & & & & & & \ & & & & & & & \ & & & & & & & \ & & & & & & & \ a & b & c & d & e & f & g & h \ \end{tblr}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Just for information: the quantikz package suffers from \expandafter frenzy: there are 484 occurrences on a total of 811 lines. – egreg Nov 26 '21 at 17:11