0

I'm having problems in fixing width of the columns in tables without the tedium of having to calculate the column widths. So I tried some solution: I used the code mentioned here. But when I apply this code to my template, the compilation stops.

Here is my sample latex online document, if you want to test the code.

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} % ragged-right version of "X"
\begin{document}

\begin{table}[]
\centering
\caption[Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo]{Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo. \\\small Fuente y elaboración propias}
\label{matriz_15m_activismo_activistas}
\begin{tabularx}{\textwidth}{@{} lLLLLL @{}}
 & Espacios & Movilización & Policía & Políticos & Represión \\ \midrule
Espacios & 0 & 8 & 39 & 10 & 36 \\
Medios & 0 & 0 & 0 & 0 & 4 \\
Movilización & 8 & 0 & 7 & 1 & 4 \\
Policía & 39 & 7 & 0 & 1 & 53 \\
Políticos & 10 & 1 & 1 & 0 & 0 \\
Represión & 36 & 4 & 53 & 0 & 0 \\ 
\end{tabularx}
\end{table}

\end{document}

closed as unclear what you're asking by Zarko, Moriambar, Werner, Mico, ebosi May 9 '17 at 23:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    your question isn't really clear enough to attempt an answer, you say you want to avoid specifying column widths but the example you show has no column widths specified so what exactly are you asking to change? – David Carlisle May 9 '17 at 21:35
  • 6
    don't make questions rely on external links it is archived here forever and will not make sense if the link changes and many of us do not follow links most of the time. – David Carlisle May 9 '17 at 21:46
  • 4
    there is no need to copy anything like all the code, just post an example of the problem that you want help with. start with a copy of the document with a table, delete all other text delete every package not needed for the example, see if whatever the problem is still happens with a standard class such as book, then post the resulting example. also compilation doesn't just "stop" it will have given an exact error message which you should show in the question in a code section so line endings are preserved. – David Carlisle May 9 '17 at 21:55
  • 1
    Side note: Your big project compiles fine for me on sharelatex when I add the \newcolumntype... line and the table code from your MWE. I cannot replicate your problem there. Also, the inputenc package is already loaded in the cls file, no need to load it again in the main tex document (just something I spotted when quickly perusing your code; not sure if there are more doubly loaded packages). And yeah, +1 for David Carlisle's advice regarding example code (I don't usually follow external links, but curiosity got the better of me in this case). Still: good luck! – alpenwasser May 9 '17 at 22:04
  • 1
    Please read the instructions in tex.meta.stackexchange.com/questions/228/… for help constructing a minimal example which we can compile to reproduce the problem you're having. – cfr May 9 '17 at 23:03
3

You mean something like

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{L}{>{\raggedright\arraybackslash}X} % ragged-right version of "X"
\begin{document}

\begin{table}
\centering
\caption[Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo]{Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo. \newline\small Fuente y elaboración propias}\label{matriz_15m_activismo_activistas}
\begin{tabularx}{\textwidth}{@{}Lccccc@{}}
\toprule
 & Espacios & Movilización & Policía & Políticos & Represión \\
 \midrule
Espacios & 0 & 8 & 39 & 10 & 36 \\
Medios & 0 & 0 & 0 & 0 & 4 \\
Movilización & 8 & 0 & 7 & 1 & 4 \\
Policía & 39 & 7 & 0 & 1 & 53 \\
Políticos & 10 & 1 & 1 & 0 & 0 \\
Represión & 36 & 4 & 53 & 0 & 0 \\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}

enter image description here

Apart from some bad column placement, and minor styles changes, I don't see many problems with your table

  • I can't obtain this table with my code project :-( – Juan Linares May 9 '17 at 20:43
  • 2
    @JuanLinares please, instead of linking external websites, try and post a minimal code sample, then, that replicates the problem, i.e., aminimal working example (MWE) – Moriambar May 9 '17 at 20:46
3

It is not very clear what you mean with result is not god :). For example, I would your table design as follows:

enter image description here

\documentclass{article}
\usepackage{booktabs, tabularx}
\usepackage{ragged2e}
\newcolumntype{C}{>{\Centering}X} % changed
\newcommand\mcx[1]{\multicolumn{1}{C}{#1}} % added for columns' headers
\usepackage{siunitx}

\begin{document}
\begin{table}
    \centering
\caption[Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo]
        {Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo. \\
        \small 
        Fuente y elaboración propias}
\label{matriz_15m_activismo_activistas}
\begin{tabularx}{\textwidth}{l *{5}{S[table-format=2.0]}}
    \toprule % ?
    & \mcx{Espacios}    & \mcx{Movilización}    & \mcx{Policía} & \mcx{Políticos} & \mcx{Represión} \\ 
    \midrule
Espacios        & 0     & 8     & 39    & 10    & 36 \\
Medios          & 0     & 0     & 0     & 0     & 4 \\
Movilización    & 8     & 0     & 7     & 1     & 4 \\
Policía         & 39    & 7     & 0     & 1     & 53 \\
Políticos       & 10    & 1     & 1     & 0     & 0 \\
Represión       & 36    & 4     & 53    & 0     & 0 \\
    \bottomrule % ?
\end{tabularx}
\end{table}
  • This table is perfect! But with the code you typed it doesn't work in my case... – Juan Linares May 9 '17 at 20:53
  • 2
    @JuanLinares, sorry, I know about your case only what you show in question. Please, edit your question and add all relevant stuff which cause that my MWE doesn't work in your "case". For now I can only claim, that it works :) – Zarko May 9 '17 at 20:55
  • I know what you mean. The problem is that with this MWE in a new document, it works, but not in my template, wich comes from sharelatex.com/templates/thesis/harvard-phd (Hardvard). Maybe there are some incompatibilities with this, in the documents .cls or .sty. I don't know :-( p.d.: thanks a lot for your effort and patience – Juan Linares May 9 '17 at 21:09
  • 1
    @JuanLinares, and how you imagine that someone can help you? – Zarko May 9 '17 at 21:16
  • I thought that providing the URL to the template online someone could check my MWE over the template, with all the complexity – Juan Linares May 9 '17 at 21:20
1

This works for me in your editor.

Edit: I want to point out that the Spanish interchange we had was basically me asking him to clarify what he wanted to achieve. It seems he wants all columns in the table to have the same width, without specifying the width column by column. I have these links to add to the discussion after some research:

Evenly distributing column widths

How do I make every column the same width?

how to fix the width of the columns in the latex table?

Forcing exactly the same column widths in table

EDIT2: Was informed that tabularxalways requires the existence of the X column. Example adjusted.

\documentclass{book}
\usepackage{tabularx}
\begin{document}
\begin{table}
\caption[Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo]{Co-ocurrencia de  temas de <<activistas>>. Actores: 15M. Día: 15 de mayo. \\\small Fuente y elaboración propias}
\label{matriz_15m_activismo_activistas}
\begin{tabularx}{\linewidth}{Xccccc}
\toprule 
~ & {Espacios} & {Movilización} & {Policía} & {Políticos} & {Represión} \\ \midrule
    Espacios & 0 & 8 & 39 & 10 & 36 \\
Medios & 0 & 0 & 0 & 0 & 4 \\
Movilización & 8 & 0 & 7 & 1 & 4 \\
Policía & 39 & 7 & 0 & 1 & 53 \\
Políticos & 10 & 1 & 1 & 0 & 0 \\
Represión & 36 & 4 & 53 & 0 & 0 \\ 
\bottomrule
\end{tabularx}
\end{table}

\begin{table}
\caption[Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo]{Co-ocurrencia de temas de <<activistas>>. Actores: 15M. Día: 15 de mayo. 
\\\small Fuente y elaboración propias}
\label{matriz_15m_activismo_activistas}
\begin{tabularx}{\textwidth}{Xccccc}
\toprule 
~ & Espacios & Movilización & Policía & Políticos & Represión \\ \midrule
Espacios & 0 & 8 & 39 & 10 & 36 \\
Medios & 0 & 0 & 0 & 0 & 4 \\
Movilización & 8 & 0 & 7 & 1 & 4 \\
Policía & 39 & 7 & 0 & 1 & 53 \\
Políticos & 10 & 1 & 1 & 0 & 0 \\
Represión & 36 & 4 & 53 & 0 & 0 \\
\end{tabularx}
\end{table}
\end{document}
  • gracias! aún así, las celdas no quedan separadas a la misma distancia, por lo que veo – Juan Linares May 9 '17 at 22:15
  • @JuanLinares, no logro entender que es lo que quieres lograr... – El Andi May 9 '17 at 22:18
  • 1
    ... pero eso es lo que estamos logrando, varios ejemplos ya logran eso, especialmente el de Zarko. Yo veo que todas las columnas tienen el mismo ancho en tu ejemplo de sharelatex (respetando el ancho del contenido de la celda). ¿Por que no pones una imagen del resultado que estas logrando? – El Andi May 9 '17 at 22:29
  • 3
    Please note that questions and answers should be in English. Examples can be in other languages, obviously, but the text of posts themselves is meant to be English. Can you edit your answer to put it in English? – cfr May 9 '17 at 23:00
  • 1
    It is also generally preferable to provide a complete minimal example whether asking a question or giving an answer. – cfr May 9 '17 at 23:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.