.png)
Ich versuche, einen Befehl zu definieren , der einen Absatz mit mehrmals wiederholten und zentrierten Buchstaben \todopar[dummy]{msg}
füllt .dummy
msg
Das Endergebnis sollte so aussehen (ohne die Abstandsprobleme)
Mein erster Versuch ist
\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}
Leider \xleaders
gelingt es mir nicht, den Blindtext in der Mittelzeile mit denen im Rest des Absatzes auszurichten. Außerdem hbox
enden die Inhalte der Füllzeilen mit einem Leerzeichen, sodass die letzte Wiederholung die Zeile ebenfalls mit einem Leerzeichen beendet.
Wie kann ich diese beiden Probleme lösen? Gibt es eine elegantere Möglichkeit, diesen Effekt zu implementieren?
Antwort1
Ich würde statt Überschriften einen Absatz verwenden:
\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}