Graphics, Figures & TablesConditional formatting based on argument

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

Conditional formatting based on argument

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}
            {}
    
        \entry
            {2010 - 2014}
            {Bachelor of Science}
            {University}
            {lorem ipsum\\
            \textit{italic textpart}}  
    \end{entrylist}
    
    \section{Section 2}

\end{document}
Based on the example before, I'd like to rewrite condition {#4} from the entry based on certain input values. In this case especially if #4 is null don't leave a blank line. Is that achievable without having to manually modify the content in the document?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Conditional formatting based on argument

Post by Johannes_B »

You can test if the argument is empty or not.

Code: Select all

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

\usepackage{etoolbox}
\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}\\
		\ifblank{#4}{}{#4\\}}\\}

	\begin{document}

	\section{Section 1}

	\begin{entrylist}
		\entry
		{2010 - 2014}
		{Bachelor of Science}
		{University}
		{}

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

		\section{Section 2}

		\end{document}
----

It seems you are working based on the friggeri-cv template. There are other templates for CVs. All of them have their own look, and are implemented a bit differently. Some use tabulars like here, some use the tabbing environment, some use simple lists.

I am working on a little pet project of mine. All personal or relevant info is stored in a simple bibtex-database. Package biblatex, which usually takes care of bibliographies, is now used to place the available data on the page. Advantage: I can define multiple predefined styles (say order of elements as well as the appearance).

A proof of concept works perfectly fine, but as i said in an earlier thread, definining macros is quite a hell, because sooner or later, something has to be changed. See latex-base, which is extended and/or modified by over 5000 different packages.
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