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 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?

share|improve this question

1 Answer 1

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

share|improve this answer
    
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 '13 at 15:07
    
a tabular set with \LTXtable{\textwidth}{mytable} and X columns will _always be of the defined width. –  Herbert Apr 28 '13 at 15:33

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.