0

I have a table like this, adapted from a template:

\begin{table}[!htbp]
\centering
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\begin{tabular}{|@{}c@{}|@{}c@{}|}
\hline
\multicolumn{1}{|c|}
{\textbf{Open Properties}} & 
\textbf{Closed Properties} \\ 
\hline 
\begin{tabular}[|c]{@{}l@{}}
What is the biggest city in USA\\ 
New York is the biggest city in USA \\ 
\hline
\end{tabular}                   
& 
\begin{tabular}[|c]{@{}l@{}}
What is the biggest city in USA\\ 
New York is the biggest city in USA \\ 
\hline
\end{tabular}
\hline
\end{tabular}
\end{table}

Which looks perfect:

enter image description here

However, for each tabular here, I had to create a \hline for its own environment. Putting a \hline for the broader overarching tabular that the nested tabulars sits in (so I don't have to define \hline 2 times, only once) messes things up. Note - similar to this - Horizontal lines in nested tabular environment but slightly different.

How do I achieve what I want without requiring multiple hlines?

  • 1
    why do you split your table into two tabulars?? It would be alot easier just to use a single tabular instead, and it would produce the same output. Unless I misunderstand what you are trying to achieve. – Runar Sep 1 '16 at 9:38
2

I do not understand what you tray to achieve. As pointed Runar Trollet, this you can achieve without nested table, for example wit changing column type c to >\centering\arraybackslash}p{<width>} (for this you need to add package array in preamble) or use tabularx and its column type X as >\centering\arraybackslash}X:

\documentclass{article}
\usepackage{tabularx}
\usepackage{caption}

    \begin{document}
\begin{table}[htb]
    \centering
    \renewcommand\arraystretch{1.5}
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\begin{tabularx}{\textwidth}{|*{2}{>{\centering\arraybackslash}X | } }
    \hline
\textbf{Open Properties} &  \textbf{Closed Properties} \\
    \hline
What is the biggest city in USA     \newline
New York is the biggest city in USA \
    &   
What is the biggest city in USA     \newline
New York is the biggest city in USA \\
    \hline
\end{tabularx}
\end{table}
    \end{document}

As you have your table and supose, that this is streap down some other, more complicated table, You can your code simplify as follows:

\documentclass{article}
\usepackage{caption}

    \begin{document}
\begin{table}[!htbp]
    \centering
    \renewcommand\arraystretch{1.5}
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\begin{tabular}{| c | c |}
    \hline
\textbf{Open Properties} &  \textbf{Closed Properties} \\
    \hline
\begin{tabular}{@{}l@{}}
What is the biggest city in USA     \\
New York is the biggest city in USA \\
\end{tabular}
    &   \begin{tabular}{@{}l@{}}
What is the biggest city in USA     \\
New York is the biggest city in USA \\
        \end{tabular}   \\
    \hline
\end{tabular}
\end{table}
    \end{document}

In both cases you obtain the same looks of table:

enter image description here

1

Does your output really look perfect? This is, of course, opinion-based, but I would suggest not to remove all space within a cell, as your text and rules are very close, even touching, making it difficult to read.

As for your table, I suggest just a regular syntax, with nothing special really. I've made a new macro to make formatting of headers a bit more consistant, and easier to change if you ever were to change your mind about how your headers should look.

I've also added an alternative approach, which gives your table a more a more professional look. Vertical lines are removed, as the reading direction here is horizontal, not vertical. The horizontal lines have been given some different and consistent weights, using \toprule, \midrule and \bottomrule from the booktabs-package. These are used above and below headers, and end of the table, not between regular rows.

I've also added the caption-package, which has some very nice features for customising your headers, and gives some better spacing by default for tables than the regular approach.

Output

enter image description here

Code

\documentclass{article}
\usepackage{caption}
\usepackage{booktabs}


\begin{document}

\newcommand{\headerFormatA}[1]{%
  \multicolumn{1}{|c|}{\textbf{#1}}
}
\newcommand{\headerFormatB}[1]{%
  \multicolumn{1}{c}{#1}
}

\begin{table}[hbt]
  \centering
  \caption{Alternative using a single tabular}
  \begin{tabular}{|l|l|}
    \hline
      \headerFormatA{Open properties} & \headerFormatA{Closed properties} \\
    \hline
    What is the biggest city in \textsc{usa}? &  What is the biggest city in \textsc{usa}? \\
    New York is the biggest city in the \textsc{usa} & New York is the biggest city in the \textsc{usa}\\
    \hline
  \end{tabular}
\end{table}

\begin{table}[hbt]
  \centering
  \caption{Improved by using \texttt{booktabs}-package}
  \begin{tabular}{ll}
    \toprule
      \headerFormatB{Open properties} & \headerFormatB{Closed properties} \\
    \midrule
    What is the biggest city in \textsc{usa}? &  What is the biggest city in \textsc{usa}? \\
    \addlinespace
    New York is the biggest city in the \textsc{usa} & New York is the biggest city in the \textsc{usa}\\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}
0
\begin{tabular}{|p{6cm}|p{6cm}|}
\hline

{\large\textbf{Open Properties}} & 
{\large\textbf{Closed Properties} }\\ 
\hline 

What is the biggest city in USA &
New York is the biggest city in USA \\ 
\hline


What is the biggest city in USA &
New York is the biggest city in USA \\ 
\hline
\end{tabular}
% this also produces the same result.

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.