TransWikia.com

newcommand does not work with tcbraster

TeX - LaTeX Asked by Arno on January 16, 2021

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

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}

Correct answer by David Carlisle on January 16, 2021

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

Answered by Ignasi on January 16, 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