0

I have the following code:

\documentclass[11pt,a4paper]{article}
\begin{document}
\begin{tabular}{p{1cm}l}
1 & 1 \\
1 & 1 
\end{tabular}
\section{Section}
\begin{tabular}{p{1cm}l}
1 & 1 \\
1 & 1 
\end{tabular}
\end{document}

For some reason that I don't understand the first table is further to the right than the second table. Here is an image:

enter image description here

I want that both tables start at the same horizontal position. Somehow the missalignment is caused by the \section command because if I replace that with some normal text the tables are aligned correctly:

\documentclass[11pt,a4paper]{article}
\begin{document}
\begin{tabular}{p{1cm}l}
1 & 1 \\
1 & 1 
\end{tabular}

Some text.

\begin{tabular}{p{1cm}l} 1 & 1 \ 1 & 1 \end{tabular} \end{document}

This code produces two tables that start at the same horizontal position:

enter image description here

I want the tables in the first image be aligned like in the second image but with a section between them.

What is causing this issue with \section and how can I fix it?

EDIT: Adding \mbox as suggested by Peter Wilson seems to fix the alignment problem but the vertical distance is then too big:

\documentclass[11pt,a4paper]{article}
\begin{document}
\begin{tabular}{p{1cm}l}
1 & 1 \\
1 & 1 
\end{tabular}
\section{Section}
\mbox{}

\begin{tabular}{p{1cm}l} 1 & 1 \ 1 & 1 \end{tabular}

\section{Section} \begin{tabular}{p{1cm}l} 1 & 1 \ 1 & 1 \end{tabular} \end{document}

enter image description here

I would like to have the same distance between table and section as in the case when there is no mbox.

Simon Dispa
  • 39,141

3 Answers3

3

In

\section{...}
\mbox{}

\begin{tabular}{...} ... \end{tabular}

the \mbox{} itself occupies a paragraph, hence the following tabuluar environment is typeset in a new paragraph, leaving a big vertical spacing.

You can set \@afterindentfalse just after sectioning title to manually allow indent-first once.

\documentclass[11pt,a4paper]{article}
\makeatletter
\newcommand\allowindent{\@afterindenttrue}
\makeatother

\newcommand\tabularDemo{% \begin{tabular}{p{1cm}l} 1 & 1 \ 1 & 1 \end{tabular} }

\begin{document} \tabularDemo

\section{Section} \tabularDemo without \verb|\allowindent|

\section{Section} \allowindent\tabularDemo with \verb|\allowindent|

\section{Section} \end{document}

enter image description here

muzimuzhi Z
  • 26,474
2

tabular is positioned by the same code that positions a letter so you are seeing the standard behaviour that the first paragraph of a section is not indented.

If you want to indent the first paragraph in all cases you could use the indentfirst package

Normally tabular if not contained in a float such as table are placed in a display environment such as center or flushleft both of which would control the indentation.

If you want normal paragraphs not to be indented after a section but do want this one, to be then you could use

\section{Section}
\indent\indent\begin{tabular}{p{1cm}l}

but I don't really recommend that.

David Carlisle
  • 757,742
2

For this outcome

a4

use this code. \noindent puts the tables on the left margins. (it might be necessary for the first after section, depends of section settings. The default for Englsh language is no indentation of the first paragraph after \section).

\documentclass[11pt,a4paper]{article}

\begin{document} \noindent \begin{tabular}{p{1cm}l} % indented normal paragraph
1 & 1 \ 1 & 1 \end{tabular}

\section{Section} \begin{tabular}{p{1cm}l} % first paragraph after section (default:no indented) 1 & 1 \ 1 & 1 \end{tabular}

\noindent\begin{tabular}{p{1cm}l} % indented second paragraph after section 1 & 1 \ 1 & 1 \end{tabular} \end{document}

The observed misalignment arises due to the confluence of three causes: the indentation rules, the document language, and the parindent value.

Indents are used to physically differentiate one paragraph from another.

Professionally printed material in English, and LaTeX by default, does not indent the first paragraph of a section. The size of the indents in subsequent paragraphs is determined by the parameter \parindent.

However, the APA style indents the first line of each paragraph, regardless of the language. (Try \documentclass[11pt,a4paper]{apa})

Likewise in French or Spanish documents, where \usepackage[spanish]{babel} or \usepackage[french]{babel} will set the proper indents (among other things).

In this case (LaTeX defaults for English documents) the first table in the MWE is indented and the second, which starts the first paragraph after a section, is not.

Another method of creating a visual separation between paragraphs is by adding extra space (usually an entire line space) between paragraphs, instead of indentation.

It is most frequently used for letters. For this use \setlength{\parindent}{0pt} will disable indentation and \setlength{\parskip}{12pt} wil add 12pt of vertical space between paragraphs.

Finally \noindent at the beggining of a paragraph will supress its indentation, but forcing an indentation is somewhat more difficult.

To indent the first paragraph after a section you neeed to use \indent\indent (see David Carlisle answer) or define a newcommand as in https://tex.stackexchange.com/a/102523/161015

Simon Dispa
  • 39,141