1

I want to keep the format of my tcb exactly as it is except I would like to squeeze it horizontally to the text width (plus an aesthetic but minimal margin.) The box should stay centered but the white space (gray actually) inside the box should be reduced.

enter image description here

\documentclass[preprint,nofootinbib]{revtex4-2}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}


\begin{document}
  
\lipsum[1]\newline


\begin{tcolorbox}[breakable]
        $~$ \newline    
        \noindent \textsf{ {\large Matthew 6:9-13 (NIV)} }
        
        \noindent \textsf{9}``This, then, is how you should pray:
        
        ``\kern 0.03em`Our Father in [\textit{the future}],
        
        hallowed be your name,
        
        \textsf{10}     your kingdom come,
        
        your will be done,
        
        $\qquad$[\textit{in the present}] as it is in [\textit{the future}].
        
        \textsf{11}     Give us today our daily bread.
        
        \textsf{12}     And forgive us our debts,
        
        $\qquad$as we also have forgiven our debtors.
        
        \textsf{13}     And lead us not into temptation,
        
        $\qquad$but deliver us from the evil one.'
        $~$ \newline    
\end{tcolorbox}


\end{document}

1
  • What about {\centering \begin{tcolorbox}[breakable,width=0.55\textwidth] in combination with a } after \end{tcolorbox}?
    – leandriis
    Mar 10 at 21:28
4

You can collect the contents and measure it with the help of varwidth that makes a tight bounding box. Then the text is typeset again to allow for breaking across pages.

\documentclass{article}
\usepackage{lipsum}

\usepackage{varwidth}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\newsavebox{\myboxbox}
\NewDocumentEnvironment{mybox}{+b}% find a better name
 {%
  \centering
  \setlength{\parindent}{0pt}%
  % measure the text width
  \sbox{\myboxbox}{\begin{varwidth}{\columnwidth}#1\end{varwidth}}%
  \begin{tcolorbox}[
    breakable,
    width=\dimexpr\wd\myboxbox+8mm,
    top=8mm,
    bottom=8mm,
  ]
  #1
  \end{tcolorbox}%
 }{}
% 4mm is the default for left and right margins inside a tcolorbox

\begin{document}
  
\lipsum[1]


\begin{mybox}
  \textsf{\large Matthew 6:9-13 (NIV)} \\[1ex]
  \textsf{9} ``This, then, is how you should pray: \\
  ``\kern 0.03em`Our Father in [\textit{the future}], \\
  hallowed be your name, \\
  \textsf{10} your kingdom come, \\
  your will be done, \\
  \hspace*{1em}[\textit{in the present}] as it is in [\textit{the future}]. \\
  \textsf{11} Give us today our daily bread. \\
  \textsf{12} And forgive us our debts, \\
  \hspace*{1em}as we also have forgiven our debtors. \\
  \textsf{13} And lead us not into temptation, \\
  \hspace*{1em}but deliver us from the evil one.'
\end{mybox}

\end{document}

Instead of $~$\newline it's better to act on the parameters top and bottom. And, instead of all those blank lines, \\ seems handier.

enter image description here

1
  • Thanks, egreg. You are really cool. Mar 10 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.