This is easy to achieve for a single line. It is also possible to do this in a parbox
, but this requires manual line breaks to work properly, which is not good for automation. Doing this automatically is much harder.
The following defines a macro \cutbox
with an optional argument for settings and a mandatory one for the text. The possible keys are
- align sets the alignment for cut and overflow lines. It can take the values
rr
(align right overflow right), ll
(align left overflow left), rl
(align right overflow left) and lr
(align left overflow right).
- cutlines sets the number of short lines from the top.
- cutwidth sets the maximum length of the cut lines.
- overflowwidth sets the maximum length for overflow lines.
- paralign sets the alignment for the surrounding
\parbox
. The possible values are t
, b
and c
.
The resulting \parbox
is cutwidth
wide and lines in there may overflow up to overflowwidth
- cutwidth
.
The result (the lines here are just for testing):
Short and long names:

Whole paragraph (with cutlines=3
):

The code:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz} % just for drawing some test lines
\usepackage{xkeyval} % for the keys
\makeatletter
% one line adjusted right overflow to the right
\newcommand*{\onelinerr}[1]{%
\hbox to \cutbox@cutwidth{\hskip0pt plus 1fill\relax #1\hskip 0pt minus 1fill}%
}
% one line adjusted left overflow to the left
\newcommand*{\onelinell}[1]{%
\hbox to \cutbox@cutwidth{\hskip0pt minus 1fill\relax #1\hskip 0pt plus 1fill}%
}
% one line adjusted right overflow to the left
\newcommand*{\onelinerl}[1]{%
\hbox to \cutbox@cutwidth{\hss #1}%
}
% one line adjusted left overflow to the right
\newcommand*{\onelinelr}[1]{%
\hbox to \cutbox@cutwidth{#1\hss}%
}
% some counters and lengths
\newcount\cutbox@cutlines
\newcount\cutbox@cutlines@cnt
\newdimen\cutbox@cutwidth
\newdimen\cutbox@overflowwidth
\newbox\cutbox@testbox
\newtoks\cutbox@resttoks
% the keys
\define@choicekey{cutbox}{paralign}[\cutbox@paralign]{t,b,c}[b]{}
\define@choicekey{cutbox}{align}[\cutbox@align]{rr,ll,rl,lr}[ll]{}
\define@key{cutbox}{cutlines}[1]{\cutbox@cutlines=#1\relax}
\define@key{cutbox}{cutwidth}[47.5mm]{\cutbox@cutwidth=#1\relax}
\define@key{cutbox}{overflowwidth}[95mm]{\cutbox@overflowwidth=#1\relax}
% initialize the keys
\setkeys{cutbox}{paralign=c,align=ll,cutlines=1,cutwidth=47.5mm,overflowwidth=95mm}
% output the remaining non cut lines
\newcommand*{\cutbox@output@restrr}{%
\hbox to \cutbox@cutwidth{\parbox[t]{\cutbox@overflowwidth}{\raggedright\the\cutbox@resttoks}\hss}%
}
\newcommand*{\cutbox@output@restll}{%
\hbox to \cutbox@cutwidth{\hss\parbox[t]{\cutbox@overflowwidth}{\raggedleft\the\cutbox@resttoks}}%
}
\let\cutbox@output@restrl\cutbox@output@restll
\let\cutbox@output@restlr\cutbox@output@restrr
% main macro
% #1: optional, setup
% #2: the text
\newcommand*{\cutbox}[2][]{%
\def\@tempa{#2}\ifx\@tempa\@empty
\else
\begingroup
\setkeys{cutbox}{#1}%
\cutbox@cutlines@cnt=\cutbox@cutlines
\expandafter\parbox\expandafter[\cutbox@paralign]{\cutbox@cutwidth}{\@cutbox{#2}}%
\endgroup
\fi
}
\newcommand*{\@cutbox}[1]{%
\cutbox@resttoks={#1 }% the space is important
\loop\ifnum\cutbox@cutlines@cnt>\z@\relax
\setbox\cutbox@testbox=\hbox{}%
\expandafter\@cutbox@collectline\the\cutbox@resttoks{} {} \@cutbox@end%
\ifdim\wd\cutbox@testbox=\z@
\cutbox@cutlines@cnt\z@
\else
\csname oneline\cutbox@align\endcsname{\unhbox\cutbox@testbox}%
\fi
\advance\cutbox@cutlines@cnt\m@ne
\repeat
\ifnum\cutbox@cutlines@cnt<\@ne
\setbox\@tempboxa=\hbox{\the\cutbox@resttoks\unskip}%
\ifdim\wd\@tempboxa=\z@
\else
\csname cutbox@output@rest\cutbox@align\endcsname
\fi
\fi
}
\def\@cutbox@collectline#1 #2 #3 \@cutbox@end{%
\setbox\cutbox@testbox=\hbox{#1}%
\ifdim\wd\cutbox@testbox>\cutbox@cutwidth
\cutbox@set@resttoks{#2}{#3}%
\else
\def\@tempa{#2}\ifx\@tempa\@empty
\cutbox@set@resttoks{#2}{}%
\else
\setbox\@tempboxa=\hbox{ #2}%
\@tempdima\wd\cutbox@testbox
\advance\@tempdima\wd\@tempboxa
\ifdim\@tempdima>\cutbox@cutwidth
\cutbox@set@resttoks{#2}{#3}%
\else
\@cutbox@@collectline#2 #3 \@cutbox@end
\fi
\fi
\fi
}
\def\@cutbox@@collectline#1 #2 #3 \@cutbox@end{%
\setbox\cutbox@testbox=\hbox{\unhbox\cutbox@testbox\space#1}%
\def\@tempa{#2}\ifx\@tempa\@empty
\cutbox@set@resttoks{#2}{}%
\else
\setbox\@tempboxa=\hbox{ #2}%
\@tempdima\wd\cutbox@testbox
\advance\@tempdima\wd\@tempboxa
\ifdim\@tempdima>\cutbox@cutwidth
\cutbox@set@resttoks{#2}{#3}%
\else
\@cutbox@@collectline#2 #3 \@cutbox@end
\fi
\fi
}
\newcommand*{\cutbox@set@resttoks}[2]{%
\cutbox@resttoks={#1 }%
\def\@tempa{#2}\ifx\@tempa\@empty
\else
\expandafter\cutbox@resttoks\expandafter=\expandafter{\the\cutbox@resttoks#2\unskip\unskip}%
\fi
}
% for easier setup
\newcommand*{\setcutbox}[1]{%
\setkeys{cutbox}{#1}%
}
\makeatother
% just for testing
\parindent0pt
\parskip2ex
\oddsidemargin2in
% setup
\setcutbox{cutwidth=40mm,overflowwidth=80mm}
\begin{document}
% draw lines for testing
\makeatletter
\newdimen\line@left@dist
\line@left@dist\cutbox@overflowwidth
\advance\line@left@dist-\cutbox@cutwidth
\begin{tikzpicture}[overlay]
\draw[blue] (0,0) -- (0,-20);
\draw[blue] (\cutbox@cutwidth,0) -- (\cutbox@cutwidth,-20);
\draw[red] (-\line@left@dist,0) -- (-\line@left@dist,-20);
\draw[red] (\cutbox@overflowwidth,0) -- (\cutbox@overflowwidth,-20);
\end{tikzpicture}
\makeatother
%-----------------------------------------------------------
\texttt{\textbf{align=rr}}
\cutbox[align=rr]{Philip Ackermann}
\cutbox[align=rr]{Prof. Dr. sci.fi. Dr. h.c. Philip Marko Maria Ackermann-Waldvogel}
%-----------------------------------------------------------
\texttt{\textbf{align=ll}}
\cutbox[align=ll]{Philip Ackermann}
\cutbox[align=ll]{Prof. Dr. sci.fi. Dr. h.c. Philip Marko Maria Ackermann-Waldvogel}
%-----------------------------------------------------------
\texttt{\textbf{align=rl}}
\cutbox[align=rl]{Philip Ackermann}
\cutbox[align=rl]{Prof. Dr. sci.fi. Dr. h.c. Philip Marko Maria Ackermann-Waldvogel}
%-----------------------------------------------------------
\texttt{\textbf{align=lr}}
\cutbox[align=lr]{Philip Ackermann}
\cutbox[align=lr]{Prof. Dr. sci.fi. Dr. h.c. Philip Marko Maria Ackermann-Waldvogel}
\newpage
% draw lines for testing
\makeatletter
\begin{tikzpicture}[overlay]
\draw[blue] (0,0) -- (0,-20);
\draw[blue] (\cutbox@cutwidth,0) -- (\cutbox@cutwidth,-20);
\draw[red] (-\line@left@dist,0) -- (-\line@left@dist,-20);
\draw[red] (\cutbox@overflowwidth,0) -- (\cutbox@overflowwidth,-20);
\end{tikzpicture}
\makeatother
% lets cut 3 lines now
\setcutbox{cutlines=3}
% a whole paragraph
\texttt{\textbf{align=rr}}
\cutbox[align=rr]{Quisque ullamcorper placerat ipsum. Cras nibh.
Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. In hac habitasse platea
dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc
elementum fermentum wisi.}
\texttt{\textbf{align=ll}}
\cutbox[align=ll]{Quisque ullamcorper placerat ipsum. Cras nibh.
Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. In hac habitasse platea
dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc
elementum fermentum wisi.}
\texttt{\textbf{align=rl}}
\cutbox[align=rl]{Quisque ullamcorper placerat ipsum. Cras nibh.
Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. In hac habitasse platea
dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc
elementum fermentum wisi.}
\texttt{\textbf{align=lr}}
\cutbox[align=lr]{Quisque ullamcorper placerat ipsum. Cras nibh.
Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. In hac habitasse platea
dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc
elementum fermentum wisi.}
\end{document}
\makebox[47.5][r]
would be an error (the first argument should be a length)\#2
would typeset#
and2