2

I have these two TeX files:

\documentclass[a3paper,landscape]{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{ltxtable}

\begin{document}
Hello.

\LTXtable{\textwidth}{mytable}

\end{document}  

and the other file autogenerates the data:

\begin{longtable}{|X|X|X|X|X|X|X|X|X|}
\caption{A very long table}\\
    \hline
    {% for col in head %}
        \textbf{ {{col | escapeTEXT}} }
        {% if not forloop.last %}
           &
        {% endif %}
    {% endfor %} 
    \\
    \hline


    {% for row in table %}
        {% for cell in row %}
            {{ cell | escapeTEXT}}
            {% if not forloop.last %} 
               &
            {% endif %}
        {% endfor %}
        \\
        \hline
    {% endfor %}
    \hline

\label{tab:LongtableOne}
\end{longtable}

This creates the table in the center which is making the columns less wide. How can I left-align the table?

  1. Also, I have to hard-code the columns like this: {|X|X|X|X|X|X|X|X|X|}.

Is it possible to make that dynamic, like in a loop?

1 Answer 1

2

use

\longtable}[l]{...}

[l] is the specifier for the horizontal alignment. However, for X columns it makes no real sense:

\RequirePackage{filecontents}
\begin{filecontents*}{xtab.tex}
\begin{longtable}[l]{@{}*3X@{}}\hline
foo & bar & baz\\\hline
\end{longtable}
\end{filecontents*}

\documentclass{article}
\usepackage{array,ltxtable}
\begin{document}
\noindent
\rule{\linewidth}{1pt}

\LTXtable{\linewidth}{xtab.tex}
\end{document}

enter image description here

2
  • i tried it but my table is still in the center. May be because i use LTX but i don't know. i mean i tried this \begin{longtable}[l]{|p{2cm}|X|X|X|X|X|X|X|X|} or u mean something else. do i need write your full line somewhere
    – user17
    Apr 28, 2013 at 15:07
  • a tabular set with \LTXtable{\textwidth}{mytable} and X columns will _always be of the defined width.
    – user2478
    Apr 28, 2013 at 15:33

You must log in to answer this question.

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