3

I'm trying to produce lines at the top and at the bottom of two cells of my tabular. The two cells both have some text in them, from which I want to take the larger cell to determine the width of both cells, hence the tabular solution.

The next step was to produce lines, for instance through the use of \hrule. For the larger cell the output is as intended: a line at the very top and at the very bottom of the tabular cell. For the smaller cell I intended to use \hfil or \hfill to flush the second \hrule towards the bottom, but \hfil seems to be discarded. What can I do to produce a line at the bottom of the first table cell, so that both lines align horizontally?

\documentclass{extarticle}

%\usepackage{multicol}
\usepackage{lipsum}
\usepackage[a4paper]{geometry}
\usepackage{xcolor}

\begin{document}

\begin{tabular}{p{\dimexpr.5\linewidth-2\tabcolsep}p{\dimexpr.5\linewidth-2\tabcolsep}}
    \textcolor{gray}{\hrule height .5pt depth .5pt}
    \bigskip
    \textsc{K E Y W O R D S}
    \hfil %\hfill
    \textcolor{gray}{\hrule height .5pt depth .5pt}
    &  \textcolor{gray}{\hrule height .5pt depth .5pt}
    \bigskip \textsc{A B S T R A C T}
    \lipsum[2]
    \textcolor{gray}{\hrule height .5pt depth .5pt}\\
\end{tabular}

%\begin{multicols}{3}
%
%\end{multicols}
\end{document}
1
  • Tabular only computes the widths, not the heights. Besides, for filling vertical space you need \vfil – egreg Sep 20 '14 at 9:50
3

You can't create cells with equal height automatically with tabular. This is a case where \valign comes handy.

\documentclass{article}

\usepackage{lipsum}
\usepackage[a4paper,showframe]{geometry}
\usepackage{xcolor}
\usepackage{microtype}

\newcommand{\keyabs}[2]{%
  \noindent
  \valign{%
    \hrule height 1pt
    \vskip .5ex
    \hsize=\dimexpr.5\linewidth-2\tabcolsep
    ##\vfil
    \vskip .5ex
    \hrule height 1pt
    \cr
    \noindent\textls{KEYWORDS} #1\cr
    \noalign{\hfill}
    \noindent\textls{ABSTRACT} #2\cr
  }\par
}

\begin{document}

\keyabs{something}{\lipsum[2]}

\end{document}

enter image description here

\valign is the “transpose” of \halign on which tabular is built upon. The showframe option is just to show the page margins (the thin rules).

If you want lightgray rules, change the code into

\newcommand{\keyabs}[2]{%
  \noindent
  \valign{%
    \hsize=\dimexpr.5\linewidth-2\tabcolsep
    \hbox to\hsize{\color{lightgray}\leaders\hrule height 1pt\hfill}\nointerlineskip
    \vskip 0.5ex
    ##\vfil\nointerlineskip
    \vskip 0.5ex
    \hbox to\hsize{\color{lightgray}\leaders\hrule height 1pt\hfill}
    \cr
    \noindent\textls{KEYWORDS} #1\cr
    \noalign{\hfill}
    \noindent\textls{ABSTRACT} #2\cr
  }\par
}

enter image description here

2
  • Accepted the answer. One question remains though: could you explain how #\vfil works? How can a token follow a hash #...?! – 1010011010 Sep 20 '14 at 10:21
  • @1010011010 It's the syntax of \halign and \valign; ## stands here for the cell body (it's doubled because we're in a definition). I added a variant for colored rules. – egreg Sep 20 '14 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.