1

I know that the package tcolorbox provides the option \tcbox. But apparently it isn't able to handle linebreaks, quotations ( e.g csquotes display equation) or mathmode content. I think that \begin{tcolorbox} is amazing and it does exactly what I want, except for adjusting its width to the content.

All I want is a command that creates an adjusted frame around an arbitrary piece of text and allows me to use linebreaks and environments like equations,quotations etc.. I don't care about pagebreaks.

Can I still achieve that with the tcolorbox package or are there other options? I'm a beginner with LaTeX, thanks in advance

EDIT: to be more precise, using the \boxed command gives me the general output I want to achieve:

\begin{equation*}
  \boxed{
   \begin{aligned}
   &p = \text{Intervallverhältnis von 1 Cent} \\
   &2 = \text{Intervallverhältnis der reinen Oktave} \\ \\
   &p^{1200} = 2 \longrightarrow p = \sqrt[1200]{2}
   \end{aligned}
  }
\end{equation*}

image of output

This is exactly what I want to achieve using tcolorbox and its frames. A frame around a (centered) piece of math, with automatically adjusted width.

I already tried using the \tcbox command:

\tcbox{
 \begin{equation*}
  \begin{aligned}
  &p = \text{Intervallverhältnis von 1 Cent} \\
  &2 = \text{Intervallverhältnis der reinen Oktave} \\ \\
  &p^{1200} = 2 \longrightarrow p = \sqrt[1200]{2}
  \end{aligned}
 \end{equation*}
}

This results in package amsmath error messages and while the frame is adjusted to its content like I want it, the whole box isn't centered anymore but aligned to the left.

  • Could you please show what you tried so far using the tcolorbox package? Please also clarify "except for adjusting its width to the content". How should the output look like? Probably a sketch could help clarify. – leandriis Mar 25 '20 at 15:14
  • 3
    If linebreaks have to be automatic, then the width needs to be fixed. You can't have both auto-width and auto-linebreaks at the same time (there is varwidth, but the width adjustment is then defined by forced line breaks, or the maximum line length—like a whole paragraph on a single line). So, you need to precisely describe what you want to do. – frougon Mar 25 '20 at 15:35
  • 1
    Have you looked at the answers to this question? – Sandy G Mar 25 '20 at 18:23
  • @leandriis I edited the post, adding an example for the output. – LinusDieLinse Mar 26 '20 at 16:15

1 Answers1

3

\tcbhighmath might be interesting for that:

enter image description here

\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\begin{equation*}
\tcbhighmath{
  \begin{aligned}
  &p = \text{Intervallverhältnis von 1 Cent} \\
  &2 = \text{Intervallverhältnis der reinen Oktave} \\ \\
  &p^{1200} = 2 \longrightarrow p = \sqrt[1200]{2}
  \end{aligned}
  }
\end{equation*}
\lipsum[4]
\end{document}

The style of the box can also be customized. \tcbset{highlight math style={colframe=black,colback=white,boxrule=1pt, sharp corners}} for example give the following output:

enter image description here

leandriis
  • 62,593
  • Thank you very much. One more question: is the \tcbset command supposed to be in the preamble? If not can I add any number of \tcbset in my code to change the appearance of each box? – LinusDieLinse Mar 26 '20 at 17:14
  • You can use the tcbset command in the preamble to change the style of all boxes in the document. Alternatively you can place the \tcbst command somewhere in the document and the style will be applied to all following boxes. – leandriis Mar 26 '20 at 18:35