Skip to content

Instantly share code, notes, and snippets.

@DGrady
Last active August 29, 2015 14:20
Show Gist options
  • Save DGrady/547d4b0dee76dab40804 to your computer and use it in GitHub Desktop.
Save DGrady/547d4b0dee76dab40804 to your computer and use it in GitHub Desktop.
Labeled rule in LaTeX
% \labeledrule[width]{Top}{Bottom}
%
% Useful for creating forms. The text above the rule is aligned to the
% surrounding baseline. A zero-width box contains the top label. The second
% command takes the bottom label and lowers it by \baselineskip, then packs it
% into a box with width zero, height of 1 em, and depth of \baselineskip plus
% the depth of the bottom label text. The height of the rule (0.4pt) is TeX's
% hard-coded height for \hrule.
\newcommand{\labeledrule}[3][\linewidth]{%
\makebox[0pt][l]{#2}%
\makebox[0pt][l]{\raisebox{-\baselineskip}[1em][\dimexpr\baselineskip+\depth\relax]{#3}}%
\rule[-2pt]{#1}{0.4pt}%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment