0

I tried using a \newcommand to get more structure in my document, but it appears, that tcolorboxes that are defined in an newcommand are not working properly in the tcbraster environment.

If I put the boxes themselfes in the tcbraster they are correctly aligned next to each other. If I use the newcommand they are below each other.

MWE:

\documentclass[utf8,fleqn]{scrartcl}

\usepackage[margin=1cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\usepackage[many]{tcolorbox}


\begin{document}



\newtcolorbox[auto counter, number format=\alph]{pabox}[2][]{%
colback=white,colframe=white,coltitle=black,title=\thetcbcounter)}


\newcommand{\bildchen}[1]{
\begin{pabox}{}
#1
\end{pabox}
}


%works side by side
\begin{tcbraster}[enhanced]
\begin{pabox}{}
testA
\end{pabox}
\begin{pabox}{}
testB
\end{pabox}
\end{tcbraster}

%does not work side by side
\begin{tcbraster}[enhanced]
\bildchen{testA}
\bildchen{testB}
\end{tcbraster}

\end{document}

How can I fix this? Can anyone help please? Thank you very much.

2 Answers 2

2

Your command includes a space before and after the box, so there is no room to get two side by side. Without the spaces, it works

\documentclass[utf8,fleqn]{scrartcl}

\usepackage[margin=1cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}% not needed in recent latex.


\usepackage[many]{tcolorbox}


\begin{document}



\newtcolorbox[auto counter, number format=\alph]{pabox}[2][]{%
colback=white,colframe=white,coltitle=black,title=\thetcbcounter)}


\newcommand{\bildchen}[1]{% no space here
\begin{pabox}{}
#1
\end{pabox}% no space here
}


%works side by side
\begin{tcbraster}[enhanced]
\begin{pabox}{}
testA
\end{pabox}
\begin{pabox}{}
testB
\end{pabox}
\end{tcbraster}

%does not work side by side
\begin{tcbraster}[enhanced]
\bildchen{testA}
\bildchen{testB}
\end{tcbraster}

\end{document}
1
  • Thank you very much.
    – user125198
    Dec 15, 2020 at 11:33
1

I don't know why OP wants to replace a tcolorbox environment by a command but if the reason is less typing, a tcbitemize can do the work.

\documentclass[utf8,fleqn]{scrartcl}

\usepackage[margin=1cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[many]{tcolorbox}

\newcounter{myboxcounter}
\setcounter{myboxcounter}{0}

\tcbset{
    mybox/.style={
        enhanced, colback=white, colframe=white, coltitle=black, 
        title={\refstepcounter{myboxcounter}\alph{myboxcounter})}}
}

\begin{document}

\begin{tcbitemize}[mybox]
\tcbitem test A
\tcbitem test B
\tcbitem test C
\tcbitem test D
\end{tcbitemize}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .