[Tex/LaTex] Breaking problem in tcolorbox — break at — breakable

line-breakingpage-breakingtcolorbox

My MWE,

\documentclass[a4paper,twoside,openany,12pt]{book}
\usepackage[left=1cm,right=1cm,top=2.5cm,bottom=2.5cm,marginparwidth=0cm,marginparsep=0cm,outer=1cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[turkish]{babel}
\usepackage{multicol}
\usepackage[listings,skins,breakable]{tcolorbox}
\usepackage{empheq}
\newcommand\B{Correct answer is \textbf{B} choice.}
\definecolor{formulzemin}{RGB}{255,255,170}
\newcommand*\mybox[1]{%
\colorbox{formulzemin}{\hspace{1em}#1\hspace{1em}}}
\newcommand{\equat}[1]{\begin{empheq}[box=\mybox]{align}{#1}\end{empheq}}

\newcommand{\kutu}[2]{\begin{tcolorbox}[enhanced jigsaw,breakable,title after break=,height fixed for=none,left=0mm,right=0mm,bottom=0mm,top=0mm,colback=red!5!white,colframe=red!75!black,enforce breakable,pad at break=1mm,break at=5cm/0cm]
\textit{{#1}
\begin{flushright}
{#2}
\end{flushright}}
\end{tcolorbox}}

\begin{document}
\begin{multicols}{2}

\kutu{A circuit element whose electrical characteristic is primarily resistive is called a resistor and is represented by the symbol shown in Fig. 2.1a. A resistor is a physical device that can be purchased in certain standard values in an electronic parts store. These resistors, which find use in a variety of electrical applications, are normally carbon composition or wire- wound. In addition, resistors can be fabricated using thick oxide or thin metal films for use in hybrid circuits, or they can be diffused in semiconductor integrated circuits. Some typical discrete resistors are shown in Fig. 2.1b. 5$:$1As the resistance is decreased and becomes smaller and smaller, we finally reach a point where the resistance is zero and the circuit is reduced to that shown in Fig. 2.3b; that is, the resistance can be replaced by a short circuit. On the other hand, if the resistance is increased and becomes larger and  arger, we finally reach a point where it is essentially infinite and the resistance can be replaced by an open circuit, as shown in Fig. 2.3c. Note that  n the case of a short circuit where \equat{V_{Ç}=V_G \cdot \frac{1}{5}=\frac{250}{5}=50\;V\!olt\nonumber}\\ \equat{V_D=V_{Ç} \cdot \sqrt{2}=50\sqrt{2}=70{,}71\;V\!olt\nonumber}}{\B}

\end{multicols}
\end{document}

And some outputs

enter image description here -> big space in left


enter image description here and enter image description here-> It can a little up


It's problem seems to break at=5cm/0cm. But I couldn't solve.

Sorry for my not good English.


@Thomas F. Sturm, your code is displaying at my computer,

enter image description hereenter image description hereenter image description here

Best Answer

First, it is important to emphasize that there is no automatic breakability for a tcolorbox inside a multicols environment. There is only the possibility to insert manual break points using the break at option. This also means that these break points have to be manually readjusted if new material is inserted before such a box. I intended this feature for short multicols environments. If many pages of material are used as your screenshots show, you will have a lot of manual adjustment.

To insert these manual break points, one has to use the break at option. Here is there relevant passage from the manual:

enter image description here

Now, your MWE uses:

break at=5cm/0cm

This results in a first break point at 5cm. All following break points are set to \textheight. This gives the expected output:

enter image description here

For this MWE, one would try to balance the columns manually by testing appropriate length values. Here, the following looks not bad:

break at=8cm

This sets all break points at 8cm. The complete source is:

\documentclass[a4paper,twoside,openany,12pt]{book}
\usepackage[left=1cm,right=1cm,top=2.5cm,bottom=2.5cm,marginparwidth=0cm,marginparsep=0cm,outer=1cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[turkish]{babel}
\usepackage{multicol}
\usepackage[listings,skins,breakable]{tcolorbox}
\usepackage{empheq}
\newcommand\B{Correct answer is \textbf{B} choice.}
\definecolor{formulzemin}{RGB}{255,255,170}
\newcommand*\mybox[1]{%
\colorbox{formulzemin}{\hspace{1em}#1\hspace{1em}}}
\newcommand{\equat}[1]{\begin{empheq}[box=\mybox]{align}{#1}\end{empheq}}

\newcommand{\kutu}[2]{\begin{tcolorbox}[enhanced jigsaw,breakable,
title after break=,
left=0mm,right=0mm,bottom=0mm,top=0mm,colback=red!5!white,colframe=red!75!black,
%enforce breakable,% <-- never use this
break at=8cm,
pad at break=1mm,
]\textit{{#1}
\begin{flushright}
{#2}
\end{flushright}}
\end{tcolorbox}}

\begin{document}
\begin{multicols}{2}

\kutu{A circuit element whose electrical characteristic is primarily resistive
is called a resistor and is represented by the symbol shown in Fig. 2.1a. A
resistor is a physical device that can be purchased in certain standard values
in an electronic parts store. These resistors, which find use in a variety of
electrical applications, are normally carbon composition or wire- wound. In
addition, resistors can be fabricated using thick oxide or thin metal films for
use in hybrid circuits, or they can be diffused in semiconductor integrated
circuits. Some typical discrete resistors are shown in Fig. 2.1b. 5$:$1As the
resistance is decreased and becomes smaller and smaller, we finally reach a
point where the resistance is zero and the circuit is reduced to that shown in
Fig. 2.3b; that is, the resistance can be replaced by a short circuit. On the
other hand, if the resistance is increased and becomes larger and arger, we
finally reach a point where it is essentially infinite and the resistance can be
replaced by an open circuit, as shown in Fig.~2.3c. Note that n the case of a
short circuit where \equat{V_{C}=V_G \cdot
\frac{1}{5}=\frac{250}{5}=50\;V\!olt\nonumber}\\ \equat{V_D=V_{C} \cdot
\sqrt{2}=50\sqrt{2}=70{,}71\;V\!olt\nonumber}}{\B}
\end{multicols}
\end{document}

The output is:

enter image description here

Finally, we can do some polishment by adding

height fixed for=all

This will set the height values of both box parts to the target value of 8cm. The complete code is:

\documentclass[a4paper,twoside,openany,12pt]{book}
\usepackage[left=1cm,right=1cm,top=2.5cm,bottom=2.5cm,marginparwidth=0cm,marginparsep=0cm,outer=1cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[turkish]{babel}
\usepackage{multicol}
\usepackage[listings,skins,breakable]{tcolorbox}
\usepackage{empheq}
\newcommand\B{Correct answer is \textbf{B} choice.}
\definecolor{formulzemin}{RGB}{255,255,170}
\newcommand*\mybox[1]{%
\colorbox{formulzemin}{\hspace{1em}#1\hspace{1em}}}
\newcommand{\equat}[1]{\begin{empheq}[box=\mybox]{align}{#1}\end{empheq}}

\newcommand{\kutu}[2]{\begin{tcolorbox}[enhanced jigsaw,breakable,
title after break=,
left=0mm,right=0mm,bottom=0mm,top=0mm,colback=red!5!white,colframe=red!75!black,
%enforce breakable,% <-- never use this
break at=8cm,
height fixed for=all,
pad at break=1mm,
]\textit{{#1}
\begin{flushright}
{#2}
\end{flushright}}
\end{tcolorbox}}

\begin{document}
\begin{multicols}{2}

\kutu{A circuit element whose electrical characteristic is primarily resistive
is called a resistor and is represented by the symbol shown in Fig. 2.1a. A
resistor is a physical device that can be purchased in certain standard values
in an electronic parts store. These resistors, which find use in a variety of
electrical applications, are normally carbon composition or wire- wound. In
addition, resistors can be fabricated using thick oxide or thin metal films for
use in hybrid circuits, or they can be diffused in semiconductor integrated
circuits. Some typical discrete resistors are shown in Fig. 2.1b. 5$:$1As the
resistance is decreased and becomes smaller and smaller, we finally reach a
point where the resistance is zero and the circuit is reduced to that shown in
Fig. 2.3b; that is, the resistance can be replaced by a short circuit. On the
other hand, if the resistance is increased and becomes larger and arger, we
finally reach a point where it is essentially infinite and the resistance can be
replaced by an open circuit, as shown in Fig.~2.3c. Note that n the case of a
short circuit where \equat{V_{C}=V_G \cdot
\frac{1}{5}=\frac{250}{5}=50\;V\!olt\nonumber}\\ \equat{V_D=V_{C} \cdot
\sqrt{2}=50\sqrt{2}=70{,}71\;V\!olt\nonumber}}{\B}
\end{multicols}
\end{document}

And the output is:

enter image description here

Related Question