1

How to center multi lines text with tcolorbox ?

~\tcolorbox_helloworld> more .\helloworld.tex
\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
  \begin{tcolorbox}[enhanced, colback=white, halign=center, valign=center, center]
    hello
    \newline
    world
  \end{tcolorbox}
\end{document}

Gives me :

enter image description here

And using extra center environnement :

~\tcolorbox_helloworld> more .\helloworld.tex
\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
  \begin{tcolorbox}[enhanced, colback=white, halign=center, valign=center, center]
    \begin{center}
      hello
      \newline
      world
    \end{center}
  \end{tcolorbox}
\end{document}

Gives me :

enter image description here

Which is still not centered !

2 Answers 2

1

Hope this will solve the issue:

\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
  \begin{tcolorbox}[enhanced, colback=white, halign=center, valign=center, center]
\centering
      hello

      world\par
  \end{tcolorbox}
\end{document}

Output

enter image description here

1
  • This does work too ! Thanks
    – fghoussen
    Commented May 11, 2021 at 8:29
1

This works for me:

\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
  \begin{tcolorbox}[enhanced, colback=white, halign=center, valign=center, center]
      hello\\
      world
  \end{tcolorbox}
\end{document}

enter image description here

1
  • It works !?... Thanks
    – fghoussen
    Commented May 11, 2021 at 8:29

You must log in to answer this question.

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