0

I am working on a machine where I currently cannot import packages. I want to fit a table into textwidth without the usual package. I managed to do this fixing the column width manually using p{2cm} as suggested here. But the problem is that then the text in the columns are not centered anymore, which I would like for all except the left one.

MWE of main document

\documentclass{article}
\begin{document}

\begin{table}
    \centering
    \input{table.tex}
\end{table}
\clearpage

\end{document}

MWE of Table

\begin{tabular}{p{2cm}p{2cm}p{2cm}}
    Hi & Hi & Hi \\
    \hline
    11 & 0 & 1111 \\
    1 & 0 & 314 \\
\end{tabular}
5
  • 2
    just use \centering in the cells and end table rows with \tabularnrwline. but you could use packages if you can write a file table.tex then you can save a copy of array.sty at the same place Commented Mar 26, 2022 at 11:23
  • I can't import files, I could retype the package code, but it's too long. Would you put \centering in each cell then?
    – Papayapap
    Commented Mar 26, 2022 at 13:14
  • you could use a standard \begin{tabular*}{\textwidth}{ccc} but why do you want to spread the columns out, it just makes the table hard to read. Commented Mar 26, 2022 at 13:29
  • Ah, tabular* is not a package? Great. The real issue is that somehow the columns stretch longer than the content of the table and thus more than textwidth. I am outputting the tex file from another software and somehow the tables are far too wide.
    – Papayapap
    Commented Mar 26, 2022 at 13:32
  • 2
    well tabular* will not help with that at all, it is for stretching tables to be wider than they would be as in the example you postd. For tables where you want line wrapping in the cells you need p columns as you show. Bu the no package requirement honestly makes no sense here, If you have laex at all you have packages such as tabularx, it is a condition of distributing latex that they are available. Commented Mar 26, 2022 at 13:35

2 Answers 2

1

One possible way is use of the tabularray package:

  • main document:
\documentclass{article}
\usepackage{tabularray}

\begin{document}

\begin{table}
    \centering
    \input{table.tex}
\end{table}

\end{document}
  • table code:
\begin{tblr}{colspec = {Q[l,wd=2cm]Q[c,wd=2cm]Q[c,wd=2cm]}}
    Hi & Hi & Hi    \\
    \hline
    11 & 0  & 1111  \\
    1  & 0  & 314
\end{tblr}

enter image description here

2
  • Thank you, but the question considered doing this without packages.
    – Papayapap
    Commented Mar 26, 2022 at 13:05
  • 1
    Sorry, what you like to have, is not possible without of them.
    – Zarko
    Commented Mar 26, 2022 at 13:09
1

I don't want to reinvent the world, but it is possible to obtain what you want with the standard package array and its wc column type (I added vertical lines in the table to make obvious the table contents are centred in their columns):

    \documentclass{article}
    \usepackage{array}

    \begin{document}

    \begin{table}
        \centering
        \input{table.tex}
    \end{table}
    \clearpage

    \end{document} 

    \begin{tabular}{|wc{2cm}|wc{2cm}|wc{2cm}|}
        Hi & Hi & Hi \\
        \hline
        11 & 0 & 1111 \\
        1 & 0 & 314 \\
    \end{tabular} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .