将 tcolorbox 压缩至文本宽度

将 tcolorbox 压缩至文本宽度

我想保持我的 tcb 的格式与原样,只是我想将其水平挤压到文本宽度(加上美观但最小的边距)。该框应保持居中,但框内的白色空间(实际上是灰色)应该减少。

在此处输入图片描述

\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

您可以收集内容并借助其进行测量,从而varwidth形成一个紧密的边界框。然后再次排版文本,以便跨页分页。

\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}

而不是$~$\newline最好根据参数top和采取行动bottom。而且,而不是所有这些空白行,\\似乎更方便。

在此处输入图片描述

相关内容