強制的に改行し、後続の各行が長くなるようにします。

強制的に改行し、後続の各行が長くなるようにします。

皆さん、こんにちは。私たちの研究所には特別なフォーマット要件があり、そのうちの 1 つを LaTex の巧妙な魔法で自動化できないかと考えています。

キャプション (セクションとサブセクションも同様) は、不揃いに設定されています。ただし、改行は、次の行が前の行よりも長くなるように行われます (維持できない場合は、最後の行を除く)。ただし、最後の行を完全に \textwith にすることを意図しているのではなく、次の行を少し長くする最初のブレークポイントを見つけます。

以下にいくつか例を挙げます。

これ:

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 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.

この種のフォーマットを自動化できるかどうか、本当に興味があります。

頑張ってください、ベルンテ

答え1

これは、最初の行が半分の幅で始まり、その後長くなります...ログに多くの警告が表示されます...

ここに画像の説明を入力してください

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

または

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

より長方形のブロックが得られます。

ここに画像の説明を入力してください

答え2

これは、最後の行の余分なスペースを置き換えるために三角形を作成しようとします。ハイフネーションを避けて常に最後の行が完全な行になるようにしたいので、まだ完璧ではありません。 を慎重に使用することで間違いを修正できます\rlap。たとえば、 ですexam\rlap{ple}

これはおそらく、 を変更するすべてのパッケージと互換性がありません\@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}

デモ

関連情報