1

First of all, my apologies for the quite large MWE; I tried to reduce it to the minimum but, given that the problem occurs quite randomly, it is difficult to maintain it.

Given the following MWE, you can see that sometime the paragraph is formatted really in a strange way --- this is just and example, but it occurs randomly that the first line is just the first word of the paragraph. See:

enter image description here

Is it possible to fix it? Or is just that tcolorbox and wrapfigure don't go well together?

MWE following:

\documentclass[11pt,a4paper,oneside,]{article}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[left=2cm, right=2cm, top=1.75cm, bottom=2.25cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{wrapfig}
\colorlet{solcolor}{green!40!black}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{lipsum}

\tcbset{common/.style={
        colback=yellow!10,
        colframe=solcolor!60,
        halign=flush left, leftrule=4mm,
}}
\newtcolorbox{solbox}[1][]{common, breakable,
    coltext=solcolor,
    #1}
\newtcolorbox{circbox}[2][]{common, nobeforeafter,
    colback=white,
    hbox, title = {#2},
    #1}

\begin{document}
\def\isr{i_\mathit{SR}}
\def\vsr{v_\mathit{SR}}
\begin{solbox}[title={Punto 2}]
    \begin{wrapfigure}{l}{0.45\linewidth}
        \centering
        \begin{circbox}{Circuito de polarización}
            \begin{tikzpicture}
                \draw (-0.5,1) rectangle ++(4.5,-6);
            \end{tikzpicture}
        \end{circbox}
    \end{wrapfigure}
    El circuito de polarización es el mismo que hemos usado para el apartado anterior;
    en este caso el condensador actúa como un circuito abierto.
    Esto implica que la tensión de polarización de $v_{O2}$ es:
    \begin{equation}
        V_{O2_Q} = 0
    \end{equation}

    Para calcular la corriente y tensión de polarización del dispositivo,
    usamos entonces el mismo procedimiento que en el punto anterior:
    \begin{align}
        V_{SR_Q} &= \text{1 V} \\
        I_{SR_Q} &= \text{1 mA}
    \end{align}

    \lipsum[1]
\end{solbox}
\end{document}
  • 2
    Don't use halign=flush left, or use halign=left instead. – Ulrike Fischer Sep 7 '18 at 13:54
  • @UlrikeFischer --- yes, it works. If you add an answer I'll happy to accept it (and if you can explain why, the better...) – Rmano Sep 7 '18 at 16:43
2

Don't use halign=flush left. This uses internally \raggedright and so allows very short lines. In combination with the parshape setting of wrapfig you get the bad linebreaking (I didn't not try to understand how TeX exactly decides the line breaking, but the problem can be demonstrated with a simple parshape too, see below). Either remove the option completly or replace it by halign=left which will use the second setting.

\documentclass{article}
\usepackage{lipsum}
\begin{document}

\rightskip=0pt plus 1fil \parindent=0pt
\parshape 9
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0pt \textwidth
\lipsum*[1]

\rightskip=0pt plus 2em \parindent=0pt %better
\parshape 9
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0.5\textwidth 0.5\textwidth
  0pt \textwidth
\lipsum*[1]


\end{document} 

enter image description here

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.