2

I'm having trouble getting the text alignment in the first column of my longtable right.

The problem is, that after a linebreak (automatic) the text is indented. More like reverse indented, since it is aligned more to the left than the first line. I want to avoid that, but can't find a solution that works. I have tried redefining via \newcolumntype and some other stuff for the last three hours and am now officially giving up :D I hope somebody can help.

This is my MWE, where the odd alignment occurs right in the first row:

\documentclass[11pt,a4paper,twoside]{scrreprt} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 

\usepackage{ragged2e,array,longtable}

\begin{document}

\begin{longtable}{|@{}p{0.35\textwidth}|p{0.15\textwidth}|p{0.5\textwidth}|}
\firsthline 
\rule[-1ex]{0pt}{2.5ex} \textbf{Software} & \textbf{Version} & 
\textbf{Copyright} \\\hline
\hline 
\rule[-1ex]{0pt}{2.5ex} Bio-Formats Package for ImageJ & 5.0.4 & The Open 
Microscopy Environment \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} GraphPad Prism 6 & 6.00 & GraphPad Software Inc., La 
Jolla, CA, USA \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} Heidelberg Eye Explorer & 1.9.13.0 & Heidelberg 
Engineering GmbH, Heidelberg, Germany \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} ImageJ & 1.45s & Wayne Rasband, NIH, Bethesda, MD, 
USA  \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} Matlab & R2016a & The MathWorks Inc., Natick, MA, 
USA \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} MC\_Rack & 4.5.9 & Multi Channel Systems MCS GmbH, 
Reutlingen, Germany \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} MC\_DataTool & 2.6.15 & Multi Channel Systems MCS 
GmbH, Reutlingen, Germany \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} Mendeley Desktop & 1.16.1 & Mendeley Desktop Ltd. \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} NeuroExplorer & 4.125 & Nex Technologies, Madison, 
AL, USA \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} Offline Sorter & 3.3.2 & Plexon Inc., Dallas, TX, 
USA \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} RC\_menu & V6.11.0.20 & Roland Consult Stasche \& 
Finger GmbH, Brandenburg a.d. Havel, Germany  \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} SAS statistical analysis software & 9.4 TS Level 1M3 
& SAS Institute Inc., Cary, NC, USA \\ 
\hline 
\rule[-1ex]{0pt}{2.5ex} Texmaker & 4.2 & Pascal Brachet \\ 
\lasthline \\
\caption[Software]{} 
\label{tab:Software}
\end{longtable}

\end{document}

Thanks so much!

Mina

  • 2
    Welcome to TeX.SE! I believe the problem comes from your \rule[-1ex]{0pt}{2.5ex} commands, what are they good for? – user121799 Jun 19 '18 at 21:36
  • I have to admit that I don't know. I used the table assistant in Texmaker to get the rough structure of the table. I just tried and deleted the \rule... stuff. Works fine now. That was easy :D Thank you so much! – Mina Meer Jun 19 '18 at 21:40
  • 1
    iot seems that \rule[-1ex]{0pt}{2.5ex} serve as strut by which is added some vertical space. if you remove space between them and following text, the indentation for one space will disappear. however, instead this rules you can use more elegant solutions, for example gaped cells from the package makecell. – Zarko Jun 19 '18 at 21:52
1

an alternative for your table:

\documentclass[11pt,a4paper,twoside]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{ragged2e}
\usepackage{booktabs, longtable, makecell}
\renewcommand\theadfont{\bfseries}
\setcellgapes{5pt} % <--- increase


%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]
\begingroup
\makegapedcells
\begin{longtable}{@{}
    >{\RaggedRight}p{\dimexpr0.27\linewidth-1.33\tabcolsep\relax}% 1.33 ~ 4/3 \tabcolsep per column
    >{\RaggedRight}p{\dimexpr0.23\linewidth-1.33\tabcolsep\relax}
    >{\RaggedRight}p{\dimexpr0.50\linewidth-1.33\tabcolsep\relax}
                 @{}   }
\caption[Software]{Overview of software packages ... }
\label{tab:Software}    \\
    \toprule
\textbf{Software} & \textbf{Version} & \textbf{Copyright} \\
    \midrule
\endfirsthead
\caption{Overview of software packages ... (cont.) }
\label{tab:Software}    \\
    \toprule
\textbf{Software} & \textbf{Version} & \textbf{Copyright} \\
    \midrule
\endhead
    \midrule
\multicolumn{3}{r}{\textit{continue on the next page}}
\endfoot
    \bottomrule
\endlastfoot
Bio-Formats Package for ImageJ
                        & 5.0.4     & The Open Microscopy Environment \\
GraphPad Prism 6        & 6.00      & GraphPad Software Inc., La Jolla, CA, USA \\
Heidelberg Eye Explorer & 1.9.13.0  & Heidelberg Engineering GmbH, Heidelberg, Germany \\
ImageJ                  & 1.45s     & Wayne Rasband, NIH, Bethesda, MD, USA  \\
Matlab                  & R2016a    & The MathWorks Inc., Natick, MA, USA \\
MC\_Rack                & 4.5.9     & Multi Channel Systems MCS GmbH, Reutlingen, Germany \\
MC\_DataTool            & 2.6.15    & Multi Channel Systems MCS GmbH, Reutlingen, Germany \\
Mendeley Desktop        & 1.16.1    & Mendeley Desktop Ltd. \\
NeuroExplorer           & 4.125     & Nex Technologies, Madison, AL, USA \\
Offline Sorter          & 3.3.2     & Plexon Inc., Dallas, TX, USA \\
RC\_menu                & V6.11.0.20& Roland Consult Stasche \& Finger GmbH, Brandenburg a.d. Havel, Germany  \\
SAS statistical analysis software
                        & 9.4 TS Level 1M3
                                    & SAS Institute Inc., Cary, NC, USA \\
Texmaker                & 4.2       & Pascal Brachet \\
\end{longtable}
\endgroup

\end{document}

which gives

enter image description here

about rules used in your table, read my comment below your question.

edit: added are code for table head, last head, foot and last foot. slightly decreased is \arraystreatch (that rows become more compact) and increased vertical spaces in cells. now the rows are better visible and use lines between rows is superfluous.

  • Although this solution looks really nice, I think I will use a version with hlines. I have some tables with seven columns (using landscape to make it fit) and find it easier to read with hlines in between rows. I was wondering if it is possible in your example to add the headings on each page. That's what \endhead does in the other example, right? When I add it after \toprule I don't get an error or something, but also no headings on the following page. – Mina Meer Jun 20 '18 at 9:03
  • @MinaMeer, yes it is possible. i will add this to my answer asap. – Zarko Jun 20 '18 at 10:09
  • @MinaMeer, see edited answer. – Zarko Jun 20 '18 at 10:43
  • I used this template for all my tables and I like it a lot. I have a problem with a very broad table, though, that I put into a landscape environment. I adjusted my captions like this: \usepackage[labelfont=bf,singlelinecheck=false,format=plain,,justification=raggedright,indention=0cm]{caption} It worked fine so far, but not in the landscape environment. The caption is shifted to the left and it looks like the table does not use all the space on the page, but less than textwidth or textheight (?) in that case. If it helps, I could post an example below. Thank you! – Mina Meer Jul 4 '18 at 8:40
  • (i) try replace all \textwidth with \linewidth (as i did in edited answer). (ii) caption with your settings had to be aligned at left text border. – Zarko Jul 4 '18 at 8:46
2

Getting rid of the mysterious \rule[-1ex]{0pt}{2.5ex} directives is a good first step. If you look closely, you'll notice that the longtable is wider than the textblock; it's necessary to reduce some of the column widths. Also, do change from full justification to raggedright layout in all three columns.

enter image description here

\documentclass[11pt,a4paper,twoside]{scrreprt} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 

\usepackage{ragged2e,array,longtable}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\setlength\extrarowheight{2pt}
\begin{document}

\begin{longtable}{|P{0.29\textwidth}|P{0.14\textwidth}|P{0.48\textwidth}|}
\hline 
\textbf{Software} & \textbf{Version} & \textbf{Copyright} \\
\hline\hline
\endhead

Bio-Formats Package for ImageJ & 5.0.4 
    & The Open Microscopy Environment \\ 
\hline 
GraphPad Prism 6 & 6.00 
    & GraphPad Software Inc., La Jolla, CA, USA \\ 
\hline 
Heidelberg Eye Explorer & 1.9.13.0 
    & Heidelberg Engineering GmbH, Heidelberg, Germany \\ 
\hline 
ImageJ & 1.45s 
    & Wayne Rasband, NIH, Bethesda, MD, USA  \\ 
\hline 
Matlab & R2016a 
    & The MathWorks Inc., Natick, MA, USA \\ 
\hline 
MC\_Rack & 4.5.9 
    & Multi Channel Systems MCS GmbH, Reutlingen, Germany \\ 
\hline 
MC\_DataTool & 2.6.15 
    & Multi Channel Systems MCS GmbH, Reutlingen, Germany \\ 
\hline 
Mendeley Desktop & 1.16.1 
    & Mendeley Desktop Ltd. \\ 
\hline 
NeuroExplorer & 4.125 
    & Nex Technologies, Madison, AL, USA \\ 
\hline 
Off{}line Sorter & 3.3.2 
    & Plexon Inc., Dallas, TX, USA \\ 
\hline 
RC\_menu & V6.11.0.20 
    & Roland Consult Stasche \& Finger GmbH, Brandenburg a.d.\ Havel, Germany  \\ 
\hline 
SAS statistical analysis software & 9.4 TS Level 1M3 
    & SAS Institute Inc., Cary, NC, USA \\ 
\hline 
Texmaker & 4.2 & Pascal Brachet \\ 
\hline

\caption[Software]{Software} 
\label{tab:Software}
\end{longtable}

\end{document}
  • Thanks, this is even better. I really appreciate the effort =) – Mina Meer Jun 20 '18 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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