0

I got a document containing multiple different exercises. Each exercise is placed in a minipage environment and included in the main document. For the first page, there is a big space between the section and the starting of the first minipage. In addition, the first minipage is indented to the left (yes I already tried to use noindent, but it doesn't make a difference). Each exercise is defined like this:

\begin{minipage}[t]{\textwidth}
exercise content here 
\end{minipage}
\vspace{0.5cm} %to create some space between exercises

Then the main file looks like this:

\section{Name of the section}
\subimport{folder}{ex1}
\subimport{folder}{ex2}
...

So the 2 problems I'm dealing with are:

  1. The space between the section and the first minipage is really big without defining space (space at the bottom wouldn't matter, for the following pages it's all right).
  2. The first minipage is indented to the left. I already tried no indent and similar commands.

Thank you for your time and help

Edit since the spacing problem is already solved, here a MWE for the indent problem:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\begin{document}
\section{This is a section title}
\begin{minipage}{\textwidth}
\textbf{Exercise}\\
Some text
\end{minipage}
\vspace{0.5cm}

\begin{minipage}{\textwidth}
\textbf{Exercise}\\
Some text
\end{minipage}
\vspace{0.5cm}

\begin{minipage}{\textwidth}
\textbf{Exercise}\\
Some tex
\end{minipage}
\vspace{0.5cm}

\begin{minipage}{\textwidth}
\textbf{Exercise}\\
Some text
\end{minipage}
\vspace{0.5cm}

\end{document}

The goal is, that all minipages are aligned the same way.

  • Welcome to TeX.SE. The first thing I can think of checking is if this still happens when you skip the importing step and instead have everything in one file. If it still happens, then that would be an easier way to post what is happening instead of asking us to create several files that will probably show the problem you're talking about. See https://tex.meta.stackexchange.com/q/228/107497 – Teepeemm May 31 '20 at 23:46
  • You say space at the bottom is no problem, so you recognize that bad page breaks are inevitable, but did you tell that to LaTeX by declaring \raggedbottom? – Donald Arseneau Jun 01 '20 at 00:26
  • Oh I didn't know that so using \raggedbottom solved the space between the first minipage and the section. Now the only problem is, that the second minipage is indented. – CrownUpKid Jun 01 '20 at 00:37

1 Answers1

1

As the first problem was solved in the comments, this answer only deal with to the second point.

The first minipage is not indented in any sense. The others are indented to the right. Change each minipage by "Foo." and you will see the same alignment:

\documentclass{article}
\begin{document}
\section{This is a section title}
Foo. 

Foo. 

Foo. 

Foo. 
\end{document}

What you have here is four paragraphs, where each paragraph it is only a box instead of many words and sentences, but that no change the indentation rules. And there are not indentation in the first paragraph after a section (in default English style), as it is always clear where it start.

The solution is add \noindent before of each minipage except to the first, or set \parindent to 0pt. That is, using still "Foo" in representation of the minipages:

\documentclass{article}
\begin{document}
\section{This is a section title}
Foo. 

\noindent Foo. 

\noindent Foo. 

\noindent Foo. 
\end{document}

...or ...

\documentclass{article}
\setlength{\parindent}{0pt}
\begin{document}
\section{This is a section title}
Foo. 

Foo. 

Foo. 

Foo. 
\end{document}

Notes:

  1. Inside the minipages, the \parindent is already 0pt and setting \parindent outside the minipages will not change that.
  2. Instead of \vspace{0.5cm}plus a blank line each time, it could be better set also\parskipin the preamble (e.g.,\setlength{\parindent}{0.5cm}`). Easier and the content is less obfusctaed by the code.
  3. Probably you are using minipages to avoid the window "Exercise" headers or orphan lines in the next page, but with or without \raggedbottom, some awful gaps will be unavoidable at some place using minipages, specially if the excercises are not very short. Probably will be better not use minipages at all, but simply \subsection*{Exercise} Some text and allow some page breaks within the long exercises.
Fran
  • 80,769
  • Avoiding minipage is good. I suggest putting \filbreak between the exercises, rather than wrapping them in minipage. – Donald Arseneau Jun 01 '20 at 05:30
  • @DonaldArseneau A think that a section heading have less penalty to page break that \filbreak, so using \subsection* or \subsubsection* instead of \textbf, \filbreak will be not necessary. – Fran Jun 01 '20 at 05:43
  • They are quite different, typically, because \raggedbottom changes nothing about the breaking of pages, only the layout after the break is chosen. The penalties in \section are usually quite ineffective against the badness of page layout. They will not ensure each exercise stays as a unit. A neat trick is to add more flexibility to the page: \addtolength{\topskip}{0pt plus0.5\textheight} will let \section keep exercises in one piece. – Donald Arseneau Jun 01 '20 at 06:38
  • @DonaldArseneau I mean that according Frank Mittelbach here the header will have priority as break point (penalty of -300 versus only -200 in \filbreak). Of course, this not avoid breaks in the middle of the exercise, but not after the header and encourage it before the header. This should be enough in many cases using also a reasonable glue in \parskip, or using the parskip package. IMHO is better deal with some problem of widow/orphan lines that destroy the consistency of the document layout with gaps everywhere. – Fran Jun 01 '20 at 07:09
  • Since avoiding breaks in the middle of an exercise is the key point of minipage, so the intent is to replicate that. As I already explained, the lower penalty does not take precedence, unless it is combined with a very large flexibility on the page (or if it happens to come very close to the bottom of the page). – Donald Arseneau Jun 01 '20 at 08:27
  • @DonaldArseneau You are missing that in my final note is because I strongly disagree with the idea that avoid the exercise break should be the key point, at least not at the cost of any gap, although I assumed that this why the OP used the minipages. You are proposing change the way of produce the gaps, but I am proposing reduce the gaps, allowing some exercise breaks but without leaving widow headers. It is a different goal with different pros and cons. – Fran Jun 01 '20 at 10:12
  • For clarification. In the real File, there are about 500+ exercises each containing maybe pictures, tables, and text. Some exercises are just one-liners, some others are filling up to a whole page. The goal is to dynamically remove or include exercises. It makes the most sense for me to wrap them into a minipage, cause most of the time the indents (even in the middle) are not sufficient for reading the exercise. For that reason it is okay to sometimes have 1/3 page in blank. – CrownUpKid Jun 01 '20 at 12:08
  • This goes back to the structures of the exercises. They are grown over time from different sources and I'm reforming the whole collection mostly via scripts. So it's not time-efficient for me to review every exercise manually and clean up the latex code behind it. But however, your response using \noindent really did the job. I tried it before, but put it in a line above \begin{minipage}{\textwidth}, not inside the same line. I didn't knew it will make any difference – CrownUpKid Jun 01 '20 at 12:11
  • @Fran It is certainly a reasonable choice to have breaking inside exercises. Your statements about "gaps everywhere" is strange, as the white fill is at the bottom of the page, especially with \filbreak. Yur statements about \section penalty taking precedence needed correcting. – Donald Arseneau Jun 01 '20 at 23:28
  • @CrownUpKid If some exercises take up a whole page and some are one line, then sometimes you can get nearly a whole page left blank, unless you allow breaks within an exercise (or manually rearrange the exercises to avoid such bad breaks). – Donald Arseneau Jun 01 '20 at 23:31
  • @DonaldArseneau By "gaps everywhere" I mean random bottom gaps across the pages. When some pages are full filled, others so-so, and others look like the end of chapters, or the end of the document, but really the next page is a bigger spoonful of the same castor oil (few people is aware of the risks of create such false expectations "What? Yet another exercise?). – Fran Jun 02 '20 at 05:47
  • The problem is, that the exercises are grown over time and from different sources. Each exercise itself is not coded correctly and has some weird spacing, which was maybe well enough for the old document but doesn't relate to the new one. I don't want to correct 500+ exercises by hand on their form factor, so this is a solution to make it a bit better, not to do it perfectly, because that would require to correct the backend of each exercise. So I can live by having some whitespaces. – CrownUpKid Jun 02 '20 at 17:52