2

I'm writing a program to parse wikimarkup to LaTeX, and I've run into a bit of an issue when it comes to creating tables. For some reason, the right vertical edge of the table is getting pushed way over into the right margin, and some of the center borders are also getting duplicated.

I tried removing the text from the rightmost cells to see if the text was somehow pushing the border over, but that seemed to make no difference. I also tried setting \textwidth to the correct value manually, but still had no luck.

This is the full LaTeX code:

\documentclass[letterpaper]{article}
\pagestyle{empty}
\usepackage[utf8]{inputenc}
\usepackage[margin=4cm]{geometry}
\usepackage{libertine, parskip, setspace, tabularx, tikz, ulem, wasysym}
\usepackage[T1]{fontenc}
\setlength\parindent{0pt}

\newcommand{\hfline}[3]{%
\par\medskip\noindent
\makebox[\textwidth][s]{\rlap{#1}\hfill#2\hfill\llap{\footnotesize{#3}}}%
\par\medskip}

\begin{document}

\begin{spacing}{0.7}
\begin{center}
\begin{scriptsize}\textbf{Declassified} per Executive Order 13526, Section 3.3\\NND Project Number: NND 63316.By: NWD Date: 2011
\end{scriptsize}
\end{center}
\end{spacing}
\begin{center}
\begin{large}
FINAL REPORT OSD \\
\end{large}
\begin{large}
Vietnam Task Force \& Index \\
\end{large}
\end{center}

\newpage
\begin{spacing}{0.7}
\begin{center}
\begin{scriptsize}\textbf{Declassified} per Executive Order 13526, Section 3.3\\NND Project Number: NND 63316.By: NWD Date: 2011
\end{scriptsize}
\end{center}
\end{spacing}
\begin{center}
\begin{Large}
EXECUTIVE SECRETARIAT \\
\end{Large}
\end{center}

\begin{tabularx}{0.7\textwidth}{X X X X X}
TLE & JJ & RMM & KDA & \fbox{ S/S-A} \\
  &   &   &   &   \\
RHM & AL & LA & NP & S/S-I \\
 &  &  &  & S/S-O \\
RTC & HHB & BF & PW & S/S-S \\
  &   &   &   &   \\
JC & TMT & JM & \fbox{ HCB} & S/S-EX \\
\end{tabularx} \\

\rule{\textwidth}{2px} \\


\begin{tabularx}{\textwidth}{X X}
\begin{large}\Square~ ACTION\end{large} & \begin{large}\Square~ INFORMATION\end{large} \\
\begin{large}\Square~ COMMENTS PLEASE\end{large} & \begin{large}\Square~ YOUR FILES\end{large} \\
\begin{large}\Square~ FOLLOW UP\end{large} & \begin{large}\Square~ PER CONVERSATION\end{large} \\
\begin{large}\CheckedBox~ PLEASE SEE/\sout{CALL ME}\end{large} & \begin{large}\Square~\end{large} \\
\end{tabularx} \\

\rule{\textwidth}{2px} \\

\begin{large}
REMARKS \\
\end{large}
\begin{center}
\begin{large}
Any S/S involvement? \\
\end{large}
\end{center}
\begin{flushright}
RTC
\end{flushright}

\rule{\textwidth}{2px} \\


\begin{tabularx}{\textwidth}{X X X}
T. L. ELIOT, JR. & R. H. MILLER & R. T. CURRAN \\
X22540 & X23126 & X28448 \\
\end{tabularx} \\

\newpage
\begin{spacing}{0.7}
\begin{center}
\begin{scriptsize}\textbf{Declassified} per Executive Order 13526, Section 3.3\\NND Project Number: NND 63316.By: NWD Date: 2011
\end{scriptsize}
\end{center}
\end{spacing}
\begin{flushright}
SecDef/CCS Regrading Action \#35---71
\end{flushright}

\begin{tabularx}{\textwidth}{*{4}{|p{0.25\textwidth}|}}
\hline
\multicolumn{2}{|p{0.5\textwidth}|}{\textbf{OFFICE OF THE SECRETARY OF DEFENSE REGRADING ACTION}} & \multicolumn{2}{|p{0.5\textwidth}|}{\textbf{\begin{footnotesize}DATE\end{footnotesize}} \newline  \newline 23 June 1971} \\ \hline 
\multicolumn{4}{|p{1.0\textwidth}|}{\textbf{\begin{footnotesize}FROM:\end{footnotesize}} \newline Top Secret Control Officer, SecDef/Classified Control Section, Room 31948, The Pentagon, Washington, D. C. 20301} \\ \hline 
\multicolumn{4}{|p{1.0\textwidth}|}{\textbf{\begin{footnotesize}TO:\end{footnotesize}} \newline State Department, ATTENTION: Document Control/Security Officer, Washington, D. C. 20520} \\ \hline 
\textbf{\begin{footnotesize}DOCUMENT\end{footnotesize}} \newline \textbf{\begin{footnotesize}(Type, Office of Origin, Date, Subject)\end{footnotesize}} & \textbf{\begin{footnotesize}CONTROL NUMBER\end{footnotesize}} & \textbf{\begin{footnotesize}CLASSIFICATION\end{footnotesize}} & \textbf{\begin{footnotesize}REGRADED TO\end{footnotesize}} \\ \hline 
Memorandum for the Secretary of Defense, Thru: ASD/ISA and DASD(Policy Planning and Arms Control), OASD(ISA), From Chairman, OSD Task Force /s/ Leslie H. Gelb, dated 15 January 1969, Subject: Final Report, OSD Vietnam Task Force (U) w/1 Inclosure::::::::: & SecDefControl\#X-0295/69 & CONFIDENTIAL & UNCLASSIFIED WHEN SEPARATED FROM INCLOSURE \\ \hline 
\textit{INCLOSURE \# 1:} \newline Document, Subject: OSD Vietnam Task Force Outline of Studies (U), dtd 10 January 1969----------------------- & " & CONFIDENTIAL & REMAINS CONFIDENTIAL \\ \hline 
\multicolumn{4}{|p{1.0\textwidth}|}{////////NOTHING FOLLOWS//////////// \newline  \newline  \newline Document was forwarded to both Mr. Bundy and Mr. Katzenback in 1969 \newline If you have any questions concerning this regrading action please contact SFC William C. Holzer, US Army, Chief Clerk, SecDef/Classified Control Section, Rm3A948, The Pentagon, Phone: OX-76131 \newline  \newline  \newline Done 7/19/71 \newline Copy in EA/Bundy file \newline Copy in 8/1-file 7512 \newline \newline  \newline } \\ \hline 
\multicolumn{4}{|p{1.0\textwidth}|}{\begin{footnotesize}The document(s) listed above has/have been regraded and action should be taken to mark copies furnished your office. It is requested that you notify all recipients to whom additional distribution was furnished.\end{footnotesize} \newline  \newline  \newline } \\ \hline 
\multicolumn{2}{|p{0.5\textwidth}|}{\textit{T. B. EDWARDS, MAJ, USA, Top Secret Control Officer} \newline \begin{footnotesize}Printed or typed name of official\end{footnotesize}} & \multicolumn{2}{|p{0.5\textwidth}|}{\begin{footnotesize}Signature\end{footnotesize}} \\ \hline 
\end{tabularx} \\
\end{document}

The table in question spans lines 97-108. The table (on page 4), looks like this:

enter image description here

3

While there are still some line-spacing issues due to the content, the following should help you on your way:

enter image description here

\documentclass{article}
%\usepackage[showframe]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\begin{tabularx}{\textwidth}{*{4}{|p{0.25\textwidth}|}}
\hline
\multicolumn{2}{|p{0.5\textwidth}|}{\textbf{OFFICE OF THE SECRETARY OF DEFENSE REGRADING ACTION}} & \multicolumn{2}{|p{0.5\textwidth}|}{\textbf{\begin{footnotesize}DATE\end{footnotesize}} \newline  \newline 23 June 1971} \\ \hline 
\multicolumn{4}{|p{1.0\textwidth}|}{\textbf{\begin{footnotesize}FROM:\end{footnotesize}} \newline Top Secret Control Officer, SecDef/Classified Control Section, Room 31948, The Pentagon, Washington, D. C. 20301} \\ \hline
\textbf{\begin{footnotesize}DOCUMENT\end{footnotesize}} \newline \textbf{\begin{footnotesize}(Type, Office of Origin, Date, Subject)\end{footnotesize}} & \textbf{\begin{footnotesize}CONTROL NUMBER\end{footnotesize}} & \textbf{\begin{footnotesize}CLASSIFICATION\end{footnotesize}} & \textbf{\begin{footnotesize}REGRADED TO\end{footnotesize}} \\ \hline 
Memorandum for the Secretary of Defense, Thru: ASD/ISA and DASD(Policy Planning and Arms Control), OASD(ISA), From Chairman, OSD Task Force /s/ Leslie H. Gelb, dated 15 January 1969, Subject: Final Report, OSD Vietnam Task Force (U) w/1 Inclosure::::::::: & SecDefControl\#X-0295/69 & CONFIDENTIAL & UNCLASSIFIED WHEN SEPARATED FROM INCLOSURE \\ \hline
\end{tabularx}

\newpage

\noindent
\begin{tabularx}{\textwidth}{|*{4}{X|}}
  \hline
  \multicolumn{2}{|p{\dimexpr0.5\linewidth-2\tabcolsep-2\arrayrulewidth}|}
    {\textbf{OFFICE OF THE SECRETARY OF DEFENSE REGRADING ACTION}} &
  \multicolumn{2}{p{\dimexpr0.5\linewidth-2\tabcolsep-\arrayrulewidth}|}
    {\textbf{\footnotesize DATE} \newline \newline 23 June 1971} \\
  \hline
  \multicolumn{4}{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}{\textbf{\begin{footnotesize}FROM:\end{footnotesize}} \newline Top Secret Control Officer, SecDef/Classified Control Section, Room 31948, The Pentagon, Washington, D. C. 20301} \\
  \hline
  \textbf{\footnotesize DOCUMENT} \newline
  \textbf{\footnotesize (Type, Office of Origin, Date, Subject)} & 
  \textbf{\footnotesize CONTROL NUMBER} & 
  \textbf{\footnotesize CLASSIFICATION} & 
  \textbf{\footnotesize REGRADED TO} \\
  \hline
  Memorandum for the Secretary of Defense, Thru: ASD/ISA and DASD(Policy Planning and Arms Control), OASD(ISA), From Chairman, OSD Task Force /s/ Leslie H. Gelb, dated 15 January 1969, Subject: Final Report, OSD Vietnam Task Force (U) w/1 Inclosure::::::::: & SecDefControl\#X-0295/69 & 
  CONFIDENTIAL & 
  UNCLASSIFIED WHEN SEPARATED FROM INCLOSURE \\
  \hline
\end{tabularx}

\end{document}

Here are some highlights in terms of the changes I've implemented in comparison to your table:

  • tabularx implements an X column type which stretches to fill the remaining space in the table, depending on the other columns and the given tabularx width. Use it.
  • \noindent stops the table from being pushed to the right as it was the first element in a paragraph, which typically requires an indent. Sure, if you set \parindent to 0pt, this doesn't matter, but this would be a general suggestion.
  • Each column that is manually set in width has to be calculated precisely in order to fit within the margin. As such, each column consists of 2 rules (of width \arrayrulewidth), 2 column separations/gaps (of width \tabcolsep) as well as the physical column width. So, in order to have a \multicolumn span of 2 columns with a rule on either side, using

    \multicolumn{2}{|p{\dimexpr0.5\linewidth-2\tabcolsep-2\arrayrulewidth}|}{...}
    

will work, since the physical width (from one rule to the next) is 0.5\linewidth.

In my example, the second \multicolumn doesn't uses only a single \arrayrulewidth. That's because the first \arrayrulewidth forms part of the first column set. - Use \footnotesize rather than the environment; it's just not necessary in this case.

The geometry package was loaded with the showframe option to highlight the text block boundary.

| improve this answer | |
  • Oh my goodness, thank you so much! I was so confused. The reasoning for using the footnotesize environment, by the way, is that I'm writing a parser to convert wikimarkup to LaTeX. It's easier to just use the environment than to check every time if there are line breaks or anything else that would confuse it. – Molly White Mar 24 '13 at 3:17

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.