1
\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{equation*}
        \begin{array}{|r|c|l|}
            \multicolumn{3}{c}{%
               AAAAAAAAAAAAA 
            }\\
            a & b & c\\
            a & b & c
        \end{array}
    \end{equation*}
\end{document}

This code outputs this:

my output

which extends the column on the right. How can I make it so that the left column and the right column are equally extended? (like "a|b|c" should be in the middle of "AAAAAA")

Example:

expected output

Toma
  • 117

1 Answers1

1

Here's a way to make LaTeX perform the column width calculations. The overall width of the array is set to the argument of the \multicolumn{3}{|c|}{...} directive. The main point is to use a column type that takes a length parameter as an argument instead of the basic l, c, and r column types.

enter image description here

\documentclass{article}

\usepackage{array} % for 'w' column type \newlength{\mylen} \settowidth\mylen{$AAAAAAAAAAAAAAA$} \addtolength\mylen{\dimexpr-4\arraycolsep-2\arrayrulewidth\relax} \setlength\mylen{\dimexpr\mylen/3\relax}

\newcolumntype{L}{w{l}{\mylen}} \newcolumntype{C}{w{c}{\mylen}} \newcolumntype{R}{w{r}{\mylen}}

\begin{document} [ \begin{array}{|R|C|L|} \multicolumn{3}{|c|}{AAAAAAAAAAAAAAA}\ \hline a & b & c\ \dots & \dots & \dots \ a & b & c \end{array} ] \end{document}


Addendum: If all you want to achieve is to typeset the a|b|c material more compactly, I suggest you pursue a nested array approach instead.

enter image description here

\documentclass{article}
\begin{document}
\[
  \begin{array}{|c|}
    AAAAAAAAAAAAA \\ 
    \hline
    \begin{array}{r|c|l}
        a & b & c\\
        a & b & c
    \end{array}
  \end{array}
\]
\end{document}
Mico
  • 506,678
  • 1
    Thank you for the detailed explanation! – Toma Oct 31 '20 at 22:45
  • One question, how should I do that without defining a fixed length? – Toma Oct 31 '20 at 23:05
  • @Toma - Please clarify what "that" refers to. Relatedly, please help me understand why you wouldn't want to use a fixed width. (Note that in the first half of the answer, the column width (\mylen) is not really fixed but is calculated dynamically.) – Mico Oct 31 '20 at 23:06
  • How can I achieve what you wrote in your answer without \settowidth\mylen{$AAAAAAAAAAAAAAA$}, so that it would work for any length of text in the multicolumn – Toma Oct 31 '20 at 23:08
  • @Toma - The \settowidth\muylen{...}, \addtolength\mylen{...}, and \setlength\mylen{...} directives don't have to occur in the preamble. They could, for instance, occur right between \[ and \begin{array}{|R|C|L|}. That way, \mylen could be updated repeatedly throughout the document, to adapt to the width of the header line of the array. Does such an approach meet your typesetting needs? – Mico Oct 31 '20 at 23:13
  • So it's not possible without a fixed length? So that the array would "adapt" its contents depending on the content's width – Toma Oct 31 '20 at 23:18
  • @Toma - I'm starting to realize that I have not at all understood what you're trying to achieve. I thought that you wanted, starting from an overall width, to assure that the widths of the three individual columns were one third of the overall width. This assumption is evidently false. Do please explain what it is that you really wish to achieve. And please be patient. – Mico Oct 31 '20 at 23:29
  • I am sorry. I have updated my question – Toma Oct 31 '20 at 23:41
  • @Toma - I've taken a look at your updated question. The addendum to my answer, which suggests using a nested-array approach, would appear to cover your updated objective. Or am i (still) missing something? – Mico Oct 31 '20 at 23:46
  • It should cover the objective if I only have one set of "inner arrays", but if I have multiple, the vertical lines would not be in the same position – Toma Nov 01 '20 at 00:27
  • @Toma - So i definitely have no idea what's going on. Sorry. Maybe un-accept my answer? – Mico Nov 01 '20 at 00:46
  • No need to, your answer applies for most cases. What I mean is if you have multiple arrays inside the main array, and those arrays have content with various widths, the vertical lines that separate the columns will not be aligned, as they are not part of the same array – Toma Nov 01 '20 at 01:22