안녕 여러분. 우리 연구소에는 몇 가지 특별한 형식 요구 사항이 있는데, 영리한 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}