.png)
여러 번 반복하여 \todopar[dummy]{msg}
단락을 채우고 단락 중앙에 조판하는 명령을 정의하려고 합니다 .dummy
msg
최종 결과는 다음과 같아야 합니다(간격 문제 없음).
나의 첫 번째 시도는
\documentclass[draft]{article}
\usepackage{lipsum}
\usepackage{xcolor}
\colorlet{todocol}{green!30!black}
\newcommand{\repetita}[1]{\leavevmode\xleaders\hbox{#1\ }\hfill\kern0pt}
\newcommand{\todopar}[2][To Do]{%
\par\medskip\noindent{%
\color{todocol!50!white}
\null\repetita{#1}\\%
\null\repetita{#1}\\%
\null\repetita{#1}%
\textcolor{todocol}{#2}%
\repetita{#1}\\%
\null\repetita{#1}\\%
\null\repetita{#1}\par\medskip%
}}
\begin{document}
\lipsum*[1]
\todopar{This is somehing we have to do soooo bad that takes even more than one line oh my gosh.}
\lipsum*[1]
\todopar{Lot of work}
\lipsum*[1]
\end{document}
불행히도 \xleaders
I를 사용하면 중앙 줄의 더미 텍스트가 나머지 단락의 텍스트와 정렬되지 않고 hbox
리더의 내용이 공백으로 끝나므로 마지막 반복에서 줄이 공백으로 끝납니다. 또한.
이 두 가지 문제를 어떻게 해결할 수 있습니까? 이 효과를 구현하는 더 우아한 방법이 있습니까?
답변1
나는 리더 대신 단락을 사용하겠습니다.
\documentclass[draft]{article}
\usepackage{lipsum}
\usepackage{xcolor}
\colorlet{todocol}{green!30!black}
\newcommand{\todopar}[2][To Do]{%
% end the previous par and start a local group
\par\medskip{%
% special para uses full length lines, no white space
% at start or end
\parindent0pt
\parfillskip0pt
% set colour for the filler text
\color{todocol!50!white}%
% save filler text in box, for measuring
\sbox0{#1 }%
%
% Set the message text in a normal paragraph with normal
% \parfillskip to allow the last line to be short as usual.
% the whole construct is inside a scratch box 2.
\setbox2\vbox{\parfillskip\fill\strut#2\unskip\strut
% Finish the paragraph with the message text
\par
% Probably not needed but remove any glue or penalty
% after the last line
\unskip\unpenalty
% remove the last (or only) line of the message paragraph
\setbox0\lastbox
%
% At this point box0 is always full width but contains the last
% line of the message followed by \rightskip and \parfillskip glue
% so \unskip twice and globally save box1 with the natural length
% of the last line of the message.
\global\setbox1\hbox{\unhbox0\unskip\unskip}%
%
% Now remove the baselineskip glue before that last line.
\unskip\unpenalty\unskip\unpenalty
% and finish the box
}%
% Now box2 contains all the lines of the message except the last
% so for a short message it will be empty
%
% see how many filler text it takes for 2 lines of text
\count0=\dimexpr2\columnwidth\relax
\divide\count0 \wd0 %
%
% see how many filler text it takes to pad one side
% of a line that has the (last line of) the message in
% the middle
\count2=\dimexpr(\columnwidth-\wd1-2em)/2\relax
\divide\count2 \wd0 %
%
% save the filler text, use a macro rather than the box
% to allow any white space in the filler to stretch
\def\tmp{\strut#1 }%
%
% make a paragraph of \count0 copies of the filler making
% a two full length line paragraph
\xrep{\count0}\par
%
% unbox box 2 this is the initial full length lines of the message
% in the main color. As this is unboxed it is a normal sequence of
% line boxes and glue so can break at a page.
{\color{todocol}\unvbox2}%
%
% Now make a 1-line paragraph with count2 copies of filler
% either side of the last line of the message, with a word space
% padding either side/
\xrep{\count2} \textcolor{todocol}{\unhbox1} \xrep{\count2}\par
%
% As before a 2 line filler paragraph
\xrep{\count0}\par%
%
% end the local group
}%
% A skip to match the one at the start.
\medskip}
% A simple recursive loop macro, makes #1
% copies of \tmp
\def\xrep#1{%
\ifnum#1>0
\tmp
\xrep{\numexpr#1-1\relax}%
\fi}
% A test document....
\begin{document}
\lipsum*[1]
\todopar{This is somehing we have to do soooo bad that takes even more than one line oh my gosh.}
\lipsum*[1]
\todopar{Lot of work}
\lipsum*[1]
\end{document}