Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I write a paper for a course and have some trouble with a table. As you can see the table fits not well into the document:

enter image description here

It would be appreciated if someone could tell me how to fix this problem. Here is a test code:

% /usr/local/doc/tex-inputs/latex/notes/paper.tex

% An example showing how to prepare an article using AMSLaTeX.
% Stephen G. Simpson, Fall 1995.
% Please send any comments or questions to simpson@math.psu.edu.

% Lines beginning with a percent sign are comments.  LaTeX ignores them.

% Begin by declaring a document class and options.

\documentclass[12pt,oneside]{amsart}

% \documentclass{amsart} says to use the AMS article document class.
% [12pt,oneside] says to use the 12pt and oneside options.
% If you don't want these options, just say \documentstyle{amsart}.

% After the document class declaration comes the preamble.
% The preamble begins here.

   % First we activate any packages that we may need.
   %
   % The amssymb package provides \mathbb and other
   % math symbols.  The amsmath package provides sophisticated math
   % constructions.  The amsthm package provides \theoremstyle and
   % the \proof environment.
   %
   % The amsmath and amsthm packages are automatically activated by
   % \documentclass{amsart}, so there is no need to activate them here.

      \usepackage{amssymb}
      \usepackage{graphicx}   % if you want to include graphics files
      \usepackage{amsmath}
      \usepackage{amsthm}
      \usepackage{amsfonts}
      \usepackage[english]{babel}
      \usepackage[utf8]{inputenc}
      \usepackage{enumerate}
      \usepackage{color}
      \usepackage[pdftex,citecolor=green,linkcolor=red]{hyperref}
      \usepackage{aliascnt}
      \usepackage{tikz}



   % Next we use \newtheorem to specify our theorem-like environments
   % (theorem, definition, etc.) and how to display and number them.
   %
   % Note: The \theoremstyle declarations affect the appearance of the
   % Theorems, Definitions, etc.

      \theoremstyle{plain}
      \newtheorem{theorem}{Theorem}[section]
      \newtheorem{lemma}[theorem]{Lemma}
      \newtheorem{corollary}[theorem]{Corollary}

      \theoremstyle{definition}
      \newtheorem{definition}[theorem]{Definition}
       \theoremstyle{proposition}
      \newtheorem{proposition}[theorem]{Proposition}

      \theoremstyle{remark}
      \newtheorem{remark}[theorem]{Remark}

   % The preamble is also a good place to define new commands and macros.
   % This part of the preamble is strictly optional according to your taste.

      \newcommand{\R}{{\mathbb R}}
      \newcommand{\nil}{\varnothing}

   % The following mysterious maneuver gets rid of AMS junk at the top
   % and bottom of the first page.

      \makeatletter
      \def\@setcopyright{}
      \def\serieslogo@{}
      \makeatother

% This ends the preamble.  We now proceed to the document itself.

\begin{document}




   \section{Test code}



\begin{proof}

 Together with the inductive result of Lemma \ref{induction} this implies in all cases that $\mathcal{P}$ is one of optimal, unbounded, or feasible:
\begin{table}[htbp]
\begin{tabular}{|cc|p{2cm}cccp{2cm}|}
\hline
\textbf{}               &            &                                                 & $\mathcal{P}/e$              & \multicolumn{1}{c|}{}                                                   \\
                        &            & optimal                                         & \multicolumn{1}{|c|}{unbonuded}      & \multicolumn{1}{|c|}{infeasible}                                        \\ \hline
                        & optimal    & optimal Lemma \ref{induction} i)                & \multicolumn{1}{|c|}{(not possible)} & \multicolumn{1}{|c|}{optimal or infeasible Lemma \ref{induction} ii)}   \\ \cline{2-5} 
$\mathcal{P}\backslash e$ & unbounded  & unbounded or optimal Lemma \ref{induction} iii) & \multicolumn{1}{|c|}{unbounded}      & \multicolumn{1}{|c|}{unbounded or infeasible Lemma \ref{induction} iv)} \\ \cline{2-5} 
                        & infeasible & (not possible)                                  & \multicolumn{1}{|c|}{(not possible)} & \multicolumn{1}{|c|}{infeasible}                                        \\ \hline
\end{tabular}
\end{table}
\end{proof}
 \bibliographystyle{plain}
   \bibliography{references}

\end{document}

You will get unresolved citation which doesn't matter.

share|improve this question
    
Use tabularx package. –  cacamailg Oct 12 '13 at 16:47
    
There are some unclear things. Do you want the P/e header on the left to encompass multiple rows or is it together with "unbounded" next to it? It might be helpful if you clarified how the cells are organized. –  Alenanno Oct 12 '13 at 16:53
add comment

2 Answers

up vote 8 down vote accepted

I suggest you simplify the table structure as follows:

  • Provide only four columns: The left-most one should be headed by $\mathcal{P}\backslash e$, and columns 2 to 4 should be headed by $\mathcal{P}/e$.
  • Don't use a tabular but, instead, a tabularx environment, and make use of the X column type provided by this package. The X column type allows text to wrap. Put differently, don't use c as the column alignment specifier.
  • Don't use full (left and right) justification; use left-justification instead.
  • You're probably going to do this anyway, but I'll still suggest you provide a \caption for the table environment.

enter image description here

\documentclass[12pt,oneside]{amsart}
\usepackage{tabularx,ragged2e}
\newcolumntype{Y}{>{\RaggedRight}X} % left-justified version of X column type
\begin{document}
\section{Test code}

Together with the inductive result of Lemma \ref{induction} this implies in all cases that $\mathcal{P}$ is one of optimal, unbounded, or feasible:
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{|X|*{3}{Y|}}
\hline
$\mathcal{P}\backslash e$ 
&\multicolumn{3}{c|}{$\mathcal{P}/e$}\\
\cline{2-4}
& optimal  &unbounded & infeasible \\ 
\hline
optimal 
& optimal Lemma \ref{induction} i) 
& (not possible)
& optimal or infeasible Lemma \ref{induction} ii)   \\ 
\hline
unbounded
& unbounded or optimal Lemma \ref{induction} iii) 
& unbounded
& unbounded or infeasible Lemma \ref{induction} iv) \\ 
\hline
infeasible 
& (not possible)                                  
& (not possible)
& infeasible \\ 
\hline
\end{tabularx}
\end{table}
\end{document}

Addendum: I'll make one more suggestion related to the overall design of the table: Don't use any vertical lines at all, and use the booktabs package and its commands for drawing well-spaced horizontal lines ("rules"):

enter image description here

\documentclass[12pt,oneside]{amsart}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{Y}{>{\RaggedRight}X} % left-justified version of X column type
\begin{document}
\section{Test code}

Together with the inductive result of Lemma \ref{induction} this implies in all cases that $\mathcal{P}$ is one of optimal, unbounded, or feasible:
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{@{}X*{3}{Y}@{}}
\toprule
$\mathcal{P}\backslash e$ 
&\multicolumn{3}{c}{$\mathcal{P}/e$}\\
\cmidrule(l){2-4}
& optimal  &unbounded & infeasible \\
\midrule
optimal 
& optimal Lemma \ref{induction} i) 
& (not possible)
& optimal or infeasible Lemma \ref{induction} ii)   \\[1ex]
unbounded
& unbounded or optimal Lemma \ref{induction} iii) 
& unbounded
& unbounded or infeasible Lemma \ref{induction} iv) \\[1ex]
infeasible 
& (not possible)                                  
& (not possible)
& infeasible \\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}

Second addendum: The OP has asked for a version of the table that features $\mathcal{P}\backslash e$ by itself in a new column at the far-left. Here's an attempt to make this work.

enter image description here

\documentclass[12pt,oneside]{amsart}
\usepackage{tabularx,ragged2e}
\newcolumntype{Y}{>{\RaggedRight}X} % left-justified version of X column type
\begin{document}
\section{Test code}

Together with the inductive result of Lemma \ref{induction} this implies in all cases that $\mathcal{P}$ is one of optimal, unbounded, or feasible:
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{|l|l|*{3}{Y|}}
\hline 
& &\multicolumn{3}{c|}{$\mathcal{P}/e$}\\
\cline{3-5}
& & optimal  &unbounded & infeasible \\ 
\hline
& optimal 
& optimal Lemma \ref{induction} i) 
& (not possible)
& optimal or infeasible Lemma \ref{induction} ii)   \\ 
\cline{2-5}
$\mathcal{P}\backslash e$
& unbounded
& unbounded or optimal Lemma \ref{induction} iii) 
& unbounded
& unbounded or infeasible Lemma \ref{induction} iv) \\ 
\cline{2-5}
& infeasible 
& (not possible)                                  
& (not possible)
& infeasible \\ 
\hline
\end{tabularx}
\end{table}
\end{document}
share|improve this answer
    
is it possible to have on the very left side another column for \mathcal{P}\backslash e$ like for $\mathcal{P}/e$ ? –  m. th Oct 12 '13 at 17:39
    
@math - It's certainly possible. What do you want to place in the new (far-left) column, and what would remain in the currently left-most column? –  Mico Oct 12 '13 at 17:42
    
In the very left should stand $\mathcal{P}\backslash e$ like on the very top row for $\mathcal{P}/e$. Such that both the very top row and the very left column look the same (for \mathcal{P}/e and \mathcal{P}\backslash e respectively.) –  m. th Oct 12 '13 at 17:44
    
@math - please see the second addendum. I must confess I'm not sure I understand your objective in adding another column to the table. –  Mico Oct 12 '13 at 18:02
add comment
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage[showframe]{geometry}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|cc|XcccX|}
\hline
A & B & CCC CCC CCC CCC CCC CCC & D & E & F & HHH HHH \\
A & B & CCC CCC CCC CCC CCC CCC & D & E & F & HHH HHH \\
\hline
\end{tabularx}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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