Força a quebra de linha, para que cada linha subsequente fique mais longa

Força a quebra de linha, para que cada linha subsequente fique mais longa

Ei pessoal. Nosso instituto tem alguns requisitos especiais de formato, e estou me perguntando se um deles pode ser automatizado por alguma magia inteligente do LaTex:

Uma legenda (também seções e subseções) é definida irregularmente à direita. No entanto, a quebra de linha é feita de tal forma que a linha subsequente é mais longa que a linha anterior (com exceção da última linha, se não for possível mantê-la). No entanto, não se pretende ter a última linha completamente \textwith, mas sim encontrar o primeiro ponto de interrupção que de alguma forma torna a próxima linha um pouco mais longa.

Então aqui estão alguns exemplos:

Esse:

This is an example of a very long caption of a figure which might be too long to stay in one line so that it will automatically jump to a new line.

Deveria ficar assim:

This is an example of a very long caption of a figure which might be too long to stay in one line so that it will automatically jump to a new line instead.

This is an example of a very long caption of a figure which might be too long to stay in one line so that it will automatically jump to a new line instead but now it is even more text.

Estou realmente curioso para saber se esse tipo de formatação pode ser automatizado.

Tudo de bom, Bernté

Responder1

isso começa com a primeira linha tendo meia largura e depois ficando mais longa... Avisa bastante no log...

insira a descrição da imagem aqui

\documentclass{article}

\usepackage{shapepar}
\makeatletter

\def\zzshape#1{%
{0}%
{0}b{0}\\%
{0}t{0}{10}\\%
{#1}t{0}{20}\\%
{#1}e{20}%
}
\def\zzzshape{\zzshape\count@}

\def\zz#1{%
\count@=1 %
\loop
\setbox0\hbox{\Shapepar\zzzshape#1\par}%
\ifdim\wd0>\linewidth
\advance\count@\@ne
\repeat
\usebox0
\par}

\begin{document}

\raggedright
\setlength\parskip\bigskipamount

\zz{%
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\zz{%
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\zz{%
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\zz{%
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\end{document}

ou com

\def\zzshape#1{%
{0}%
{0}b{0}\\%
{0}t{0}{17}\\%
{#1}t{0}{20}\\%
{#1}e{20}%
}

você obtém um bloco mais retangular:

insira a descrição da imagem aqui

Responder2

Isto tenta criar um triângulo para substituir o espaço extra na última linha. Não totalmente aperfeiçoado, pois gostaria de evitar a hifenização e sempre terminar com uma linha completa por último. É possível corrigir erros pelo uso cuidadoso de \rlap. Por exemplo, exam\rlap{ple}.

Provavelmente isso é incompatível com todos os pacotes que modificam o \@makecaption.

\documentclass[12pt]{article}

\makeatletter
\long\def\@makecaption#1#2{\bgroup
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa < \hsize
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \else
    \ifdim \wd\@tempboxa < 2\hsize
      \dimen0=\dimexpr \wd\@tempboxa - \hsize\relax
      \parshape=2 0pt \dimen0 0pt \hsize
      #1: #2\par
    \else
      \count1=\numexpr \wd\@tempboxa/\hsize\relax% number lines
      \dimen0=\dimexpr \count1\hsize - \wd\@tempboxa\relax% extra space      
      \ifdim \dimen0 < 0pt
        \advance \count1 by 1
        \advance \dimen0 by \hsize
      \fi
      \count2=\numexpr \count1-1\relax
      \dimen1=\dimexpr 2\dimen0/\count1/\count2\relax% increment
      \ifdim\dimen1 < 2em\relax
        \count2=\count1
        \advance\count1 by 1
        \advance\dimen0 by \hsize
        \dimen1=\dimexpr 2\dimen0/\count1/\count2\relax
      \fi
      \dimen2=\dimexpr \hsize - \count2\dimen1\relax
      \edef\@makecaptionparshapeargs{\the\count1}% \parshape arguments
      \loop\ifnum\count1>0\relax
        \edef\@makecaptionparshapeargs{\@makecaptionparshapeargs\space0pt \the\dimen2}%
        \advance\count1 by -1
        \advance\dimen2 by \dimen1
      \repeat
      \parshape=\@makecaptionparshapeargs
      #1: #2\par
    \fi
  \fi
  \vskip\belowcaptionskip
\egroup}
\makeatother

\begin{document} 
\begin{figure}
\caption{Short cpation.}

\caption{This is an example of a very long caption of a figure which might be
too long to stay in one line.}

\caption{This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\caption{This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}

\caption{This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.
This is an example of a very long caption of a figure which might be
too long to stay in one line so that it will automatically jump to a
new line.}
\end{figure}
\end{document}

demonstração

informação relacionada