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 trying to typeset a matrix which has entries of differing widths. However, for aesthetic reasons, I would like each of the columns of the matrix to be the same width, and I'd furthermore like them to be right-aligned.

I'm working in the tabularx environment (because of its ability to adjust column width uniformly). However, if I compile

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tabularx}

\begin{document}

\[
\left[
\begin{tabularx}{1in}{XXX}
x & 0 & y\\
0 & y & -x
\end{tabularx}
\right]
\]

\end{document}

then the columns don't have the desired justification. I looked through the tabularx documentation and discovered that I should define a new column type. So I tried the following:

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tabularx}

\begin{document}

\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\[
\left[
\begin{tabularx}{1in}{RRR}
x & 0 & y\\
0 & y & -x
\end{tabularx}
\right]
\]

\end{document}

This produced no change in output. What am I missing?

EDIT: The following code

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tabularx}

\begin{document}

\newcolumntype{P}{>{\raggedleft\arraybackslash }p{.075in}}
\newcolumntype{Q}{>{\raggedleft\arraybackslash $}p{0.075in}<{$}}

$\left[\begin{array}{PPP}
x & 0 & y\\
0 & y & -x
\end{array}\right]$    
\qquad    
$\left[\begin{array}{QQQ}
x & 0 & y\\
0 & y & -x
\end{array}\right]$

\end{document}

produces THIS output:

enter image description here

share|improve this question

1 Answer 1

up vote 2 down vote accepted

First, you are missing mathmode in your example. You need \[/\] around the \left[/\right].

This produced no change in output. What am I missing?

On my machine it produces a change! The columns are right aligned.

The tabularx is not really meaningful if you use X for ALL columns. In this case just use p{<width>} columns with a normal tabular or array environment, e.g.:

  \newcolumntype{P}{>{\raggedleft\arraybackslash}p{.2in}}
  \begin{array}{PPP}

On my installation this gives almost the same result as your second code with the R column:

enter image description here

Edit: Answer to your edited problem:

The first can be fixed with \hbox{-x} and the second one with \!\!-x.

I don't think you will avoid manual adjustments here. However, with this small sizes the result will not look very nice, and LaTeX is normally about good typesetting quality.

share|improve this answer
1  
Thanks for pointed out the lack of math-mode. I corrected the minimal example. I tried your suggestion of using array instead. The problem is that I am under size restrictions and need my columns to be fairly narrow. For some reason array doesn't like this, and has wrapped the {2,3} entry of the matrix. How can I force the entire entry to be on one line, even if the {2,2} and {2,3} entries are fairly close together? –  Kristen Jan 28 '11 at 18:03
    
Could you please reproduce this in your minimal example. –  Martin Scharrer Jan 28 '11 at 18:07
    
The statement of the question has been edited to include the example. –  Kristen Jan 28 '11 at 22:25
    
@Kristen: Thanks, I added possible solutions for that to my answer. –  Martin Scharrer Jan 28 '11 at 22:40
    
Thanks. I managed to get what I wanted, but with a lot of manipulation, etc. –  Kristen Jan 28 '11 at 23:02

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.