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'm using the array environment and have something like this:

\begin{array}{|c|c|}
   \hline 
   \textbf{x} & \textbf{y} \\ 
   \hline
   \hline
   t_1 & lon_1 \\ 
   \hline 
\end{array}

I would like to have the two columns to have the same width. How can I do that?

share|improve this question
    
One way would be to use p{1.0cm} as in \begin{tabular}{|p{1.0cm}|p{1.0cm}|}, which necessitates the content being in math mode: $t_1$. –  Peter Grill May 8 '12 at 18:12
    
@MarcoDaniel: Good point. I dislike this solution as you have to fix the width, and have to do additional tweaking if you want to switch from l, to c to r alignment, but only mentioned it as an option. –  Peter Grill May 8 '12 at 18:21
add comment

1 Answer 1

up vote 6 down vote accepted

If you don't want to use the the p{<width>} column type where you have to fix the width to a specific amount you could typeset one row using the SetToWidest macro as defined below. This requires that you determine what the widest entry is and define that as the value of WidestEntry:

enter image description here

\documentclass{article}
\usepackage{calc}

\newcommand{\WidestEntry}{$lon_1$}%
\newcommand{\SetToWidest}[1]{\makebox[\widthof{\WidestEntry}]{#1}}%

\begin{document}
\begin{tabular}{|c|c|}
   \hline 
   \textbf{x} & \textbf{y} \\ 
   \hline
   \hline
   \SetToWidest{$t_1$} & $lon_1$ \\ 
   \hline 
\end{tabular}

or similarly using array:

\documentclass{article}
\usepackage{calc}

\newcommand{\WidestEntry}{$lon_1$}%
\newcommand{\SetToWidest}[1]{\makebox[\widthof{\WidestEntry}]{$#1$}}%

\begin{document}$
\begin{array}{|c|c|}
   \hline 
   \textbf{x} & \textbf{y} \\ 
   \hline
   \hline
   \SetToWidest{t_1} & lon_1 \\ 
   \hline 
\end{array}$
\end{document}

If you are ok with specifying the width of each column you can use the p{<width>} column type:

\documentclass{article}
\usepackage{array}

\begin{document}$
\begin{array}{|>{\centering\arraybackslash$} p{1.0cm} <{$} | >{\centering\arraybackslash$} p{1.0cm} <{$} |}
   \hline 
   \textbf{x} & \textbf{y} \\ 
   \hline
   \hline
   t_1 & lon_1 \\ 
   \hline 
\end{array}$
\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.