2

I'm trying to write a diary of a journey I did in the past but I'm facing a problem with paragraph identation and page breaks. I've written the following command (\EntradaDiario)

\newcommand{\Separador}{
    {\noindent\begin{center}
        $\ast~\ast$
    \end{center}}
}
\newcommand{\EntradaDiario}[7]{
    %% Header section -----------------------------------------------------------------
    {\footnotesize \mbox{\textit{#6} : #2 $\xrightarrow{#3~\text{km.}}$ 
    #5.}\hfill\makebox[1.6cm][r]{\textit{#4~km.}}}
                                                  % <-------- Page breaks allowed here?
    %% Body of the diary for one day: -------------------------------------------------
    \textbf{#1~}$\rightarrowtail$~#7
    \Separador
}

Which when used, results in something like this:

\EntradaDiario{Title}{Location1}{10}{20}{Location2}{Date}{\lipsum[1]}

Result after compiling the example

I do want the header and the first line of the body section to have no indentation, whereas the rest of the text (even if it has several paragraphs) has to be indented. My problem is that the line break between the header and body sections can cause a page break, and I want to avoid that. What would be the best way to prevent this behaviour?

Also, how could I force new paragraphs inside the body section (the actual text) to also have the first line with the same indentation than the rest of the text?

  • Just to clarify: There are parts where you are using the complete textwidth? Have you checked packages like scrextend and the addmargin environment? – Johannes_B Sep 3 '15 at 17:18
2

I use xgalley in the example below to format the page layout.

In order to keep the "header" and "first line of body text" together, I use needspace, requesting at least the availability of 2\baselineskip. You might want to change this slightly, depending on your layout and how the height of \xrightarrow spans vertically, but the principle is sound.

enter image description here

\documentclass{article}
\usepackage{xgalley,amsmath,amssymb,needspace}
\usepackage{lipsum,geometry}% Just for this example
\geometry{showframe,paperheight=25\baselineskip}

% http://river-valley.zeeba.tv/media/conferences/tug-2015/0302-Joseph-Wright/
\ExplSyntaxOn
\cs_new_eq:NN \SetAbsMargins \galley_margins_set_absolute:nn  % left, right
\cs_new_eq:NN \SetRelMargins \galley_margins_set_relative:nn  % left, right
\cs_new_eq:NN \SetAllShape   \galley_parshape_set_multi:nnnN  % Normal, left, right, resume
\cs_new_eq:NN \SetOneShape   \galley_parshape_set_single:nnnN % Normal, left, right, resume
\cs_new_eq:NN \CutoutLeft    \galley_cutout_left:nn           % Normal, indents
\cs_new_eq:NN \CutoutRight   \galley_cutout_right:nn          % Normal, indents
\cs_new_eq:NN \True          \c_true_bool
\cs_new_eq:NN \False         \c_false_bool
\ExplSyntaxOff

\newcommand{\Separador}{%
  \noindent\hfill$\ast~\ast$\hfill\mbox{}%
}
\newenvironment{EntradaDiario}[6]{{%
  \par
  \Needspace{2\baselineskip}
  \hspace*{-3em}% Indent into margin
  %% Header section -----------------------------------------------------------------
  {\footnotesize \mbox{\textit{#6} : #2 $\xrightarrow{#3~\text{km.}}$ 
  #5.}\hfill\makebox[1.6cm][r]{\textit{#4~km.}}}
  \par\nobreak
  %% Body of the diary for one day: -------------------------------------------------
  \hspace*{-3em}\textbf{#1~}$\rightarrowtail$~\ignorespaces
}}{\unskip\par\nobreak\Separador\par\medskip}

\setlength{\parindent}{0pt}
\AtBeginDocument{%
  \SetAbsMargins{3em}{0pt}
}

\begin{document}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[7]
\end{EntradaDiario}

\end{document}

You'll also see that I've converted EntradaDiaro to be an environment rather than a macro. It made more sense since it may contain (multi-)paragraph text.

|improve this answer|||||
  • Nice, \Needspace did the job! Thanks a lot! – Carles Araguz Sep 4 '15 at 11:34
0

Here is a relatively package free approach. Page breaking is prevented for three lines by overlaying the first three lines with an large strut. I don't know how needspace works, but have been using this trick for some time now.

The hanging indentation was achieved using \leftskip and negative \hspace (\hangindent only affects one paragraph). I changed it to an environment for the same reasons as Werner. I simplified \Separador just to fit it into one line.

\documentclass{article}
\usepackage{showframe}
\usepackage{amsmath,amssymb}
\usepackage{lipsum}

\newcommand{\Separador}{\par\noindent\hfil{$\ast~\ast$}\par}

\newenvironment{EntradaDiario}[6]{\par\rule{0pt}{3\baselineskip}\vspace{-3\baselineskip}\newline
    \leftskip=\bibindent
    \hspace*{-\leftskip}%
    %% Header section -----------------------------------------------------------------
    {\footnotesize\mbox{\textit{#6} : #2 $\xrightarrow{#3~\text{km.}}$ 
    #5.}\hfill\makebox[1.6cm][r]{\textit{#4~km.}}}\linebreak
    %% Body of the diary for one day: -------------------------------------------------
    \hspace*{-\leftskip}\textbf{#1~}$\rightarrowtail$~\ignorespaces}
 {\Separador}

\begin{document}
\rule{1pt}{43\baselineskip}\par% test page breaking
\begin{EntradaDiario}{Title}{Location1}{10}{20}{Location2}{Date}
\lipsum[1-2]
\end{EntradaDiario}
\end{document}

cropped page

|improve this answer|||||

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.