Graphics, Figures & TablesLine break after each entry but last

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Line break after each entry but last

Post by thag1987 »

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}

\setlength{\tabcolsep}{0cm}
\newenvironment{entrylist}{
	\begin{tabular*} % create table
		{\textwidth}{@{\extracolsep{0.2cm}}ll} % two columns left-aligned with 0.2cm space in between
}{
	\end{tabular*}
}

\newcommand{\entry}[4]{
        #1&\parbox[t]{10cm}{
        \textbf{#2}
        \hfill
        {\footnotesize #3}\\
        #4\\}\\}

\begin{document}

    \section{Section 1}

    \begin{entrylist}
        \entry
            {2010 - 2014}
            {Bachelor of Science}
            {University}
            {lorem ipsum\\
             \textit{italic textpart}}
    
        \entry
            {2010 - 2014}
            {Bachelor of Science}
            {University}
            {lorem ipsum\\
            \textit{italic textpart}}  
    \end{entrylist}
    
    \section{Section 2}

\end{document}
This snipped puts a line break after each entry, which adds up to two line breaks before 'Section 2', where I'd like ideally only one to occur. Can I change this in the command? Is there something like the last-child selector in CSS?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Line break after each entry but last

Post by Johannes_B »

LaTeX just expands macros.

There are multiple new-line triggers active.

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}

\setlength{\tabcolsep}{0cm}
\newenvironment{entrylist}{
	\begin{tabular*} % create table
		{\textwidth}{@{\extracolsep{0.2cm}}ll} % two columns left-aligned with 0.2cm space in between
	}{
	\end{tabular*}
}

\newcommand{\entry}[4]{
	#1&\parbox[t]{10cm}{
		\textbf{#2}
		\hfill
		{\footnotesize #3}\\
	#4}\\
}

\begin{document}

\section{Section 1}

\begin{entrylist}
	\entry
	{2010 - 2014}
	{Bachelor of Science}
	{University}
	{lorem ipsum\\
		\textit{italic textpart}
	}

	\entry
	{2010 - 2014}
	{Bachelor of Science}
	{University}
	{lorem ipsum\\
		\textit{italic textpart}
	}
\end{entrylist}

\section{Section 2}

\end{document}
A template is a fixed thing, a fixed layout, fixed input. Fill out the blanks, live with the result.

It seems, you are not happy with the current layout. You are investing work and time into this. This is ok. I think you will achieve good results quicker doing everythiing by hand not using a template at all. ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Re: Line break after each entry but last

Post by thag1987 »

I can't stop now ;)

But I think I get the hang of it slowly. Should have figured out most of the template and have adjusted the structure. Just have to learn all the tweaks now to make it perfect.

Any hint on the line break?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Line break after each entry but last

Post by Johannes_B »

I removed one in the code above. In order to have more control, you have to add an additional argument to the definition of the entry command to define the spaces.

This is the curse of macros, you gain something (time?) and loose something (control). The same goes for templates. A template is (in my pov) a predefined (visual) style, changing that style is often a real pain. Especially since templates are used almost exclusively by starters.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Re: Line break after each entry but last

Post by thag1987 »

Problem with the removed one is that it removes the space after each entry, instead of just after the last entry.

That would obviously work if you add the line break manually after each (but the last) entry. But that's not very 'clean'.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Line break after each entry but last

Post by Johannes_B »

Sorry, but i think there is no completely automatic solution.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Re: Line break after each entry but last

Post by thag1987 »

:( ok, I'll leave it for now in this case.

In a perfect scenario I'd like to have no formatting in the document at all. Just text formatted by references on the macros.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Line break after each entry but last

Post by Johannes_B »

Look at the example that you gave above, i added a rule. Maybe you should adjust the skip before a section heading.

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}

\setlength{\tabcolsep}{0cm}
\newenvironment{entrylist}{
	\begin{tabular*} % create table
		{\textwidth}{@{\extracolsep{0.2cm}}ll} % two columns left-aligned with 0.2cm space in between
	}{
	\end{tabular*}
}

\newcommand{\entry}[4]{
	#1&\parbox[t]{10cm}{
		\textbf{#2}
		\hfill
		{\footnotesize #3}\\
	#4\\}\\
}

\begin{document}

\section{Section 1}

\begin{entrylist}
	\entry
	{2010 - 2014}
	{Bachelor of Science}
	{University}
	{lorem ipsum\\
		\textit{italic textpart}
	}

	\entry
	{2010 - 2014}
	{Bachelor of Science}
	{University}
	{lorem ipsum\\
		\textit{italic textpart}
	}
\end{entrylist}
\rule{.5\textwidth}{1pt}

\section{Section 2}

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply