Hipster CV – A Template

Dear all,

sorry you haven’t been hearing from me so much lately. It’s been quite busy. To make it up to you, I wanted to share my hipster CV template on this occasion 😉 I will probably explain it later and also probably modify it in a way that it’s easiert to use for a beginner. If you want to use it and but don’t feel comfortable with how the template works, just check where the text you are looking to replace is in the main.tex and replace it with your content. That way, you should get away with fairly limited LaTeX skills and still be able to use the template if you want it.

hipster-cv

 

It is available on the newly created LaTeX Ninja Github! The template is not exactly the same as shown in the Teaser: LaTeX Resumé Template Preview.

hipster-cv-github

 

So you can look forward to more versions which will be kind of the same style. But I now have so many different elements that I could fill at least 10 different CV templates. Since I didn’t want to fall victim to my own perfectionism, I dedided to share the template now even though it could probably be better. It also doesn’t really comply with my own standards regarding good code, etc. 😉 Well, you can’t always have it all.

It is, however, more of a Saturday afternoon fun thing I did. I won’t give any recommendations as to whether it will be considered as appropriate in your field of work to actually use this CV 😉

Also, I hope I am allowed to have the Jack Sparrow images in the example. I am not so sure about it however. Come visit me in prison if this should go wrong 😉

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

Advertisements

XML to LaTeX (simple)

Today, I wanted to share this super simple XML to LaTeX tutorial. Using XSLT, you are going to transform XML data to LaTeX output which you can then go on to compile into your desired output PDF. There will be no fancy stuff whatsoever in this post, just the basics and what to keep in mind with these transformations. It is the quick intro to XML to LaTeX I did with my students a while ago which was done one day after they had their first contact with XSLT, so it should really be beginner-friendly. I labeled it “Advanced LaTeX” anyway because I think starting to automate things is always a step in the right direction 😉

Configuring the transformation scenario in Oxygen

I am going to assume you use Oxygen now because that’s what a lot of people in the DH do and this post is directed towards my friends in the DH. Especially those who think print editions are an obsolete concept in times of the Digital Edition. Maybe having a nice little intro to XML to LaTeX transformations available will change their minds 😉

To set up the transformation scenario, choose XML transformation using XSLT, then choose your XML document and your XSL stylesheet (set up and open those document in the editor before you configure the scenario). Then choose a Saxon 9 version (whichever you like). Then ignore the FO tab and get right to the output tab.

Here you configure how to name your output. Best click the green arrow and choose cfn, then append -latex.tex. So the result the current filename with -latex.tex appended to it. This is an important step so you don’t accidentally overwrite the original. Which in this case is not so dramatic since it has a different ending anyway but if you do XML to XML transformations, this is even more crucial. Then tell Oxygen to show it in the editor as XML (even though you know it isn’t). The editor will then, of course, complain about the non-valid XML but don’t worry. Just copy all (CTRL+ACTRL+C) and paste it (CTRL+V) into a completely empty (!) project in Overleaf  or just compile the LaTeX directly if you have it installed on your machine.

There it is, you’re set. Now let’s get to the stylesheet.

The stylesheet

So, this is the whole thing. You can just grab it and go if you don’t care for the explanation or read on to find out why things were done the way they were done. This tutorial assumes you’re already familiar with how XSLT works, just haven’t done transformations to LaTeX yet, by the way. I am also assuming, your base XML is in the TEI standard.

 

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema"     xmlns:t="http://www.tei-c.org/ns/1.0"     exclude-result-prefixes="xs"     version="2.0">
    <xsl:strip-space elements="*"/>
    <xsl:output method="text" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:text>\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\DeclareUnicodeCharacter{2060}{\nolinebreak} % might not be necessary for you

\title{</xsl:text><xsl:apply-templates select="//t:title"/>
        <xsl:text>}
\author{</xsl:text><xsl:apply-templates select="//t:author"/>
        <xsl:text>}\date{\today}
\begin{document}
\maketitle
\tableofcontents\newpage</xsl:text>
        <!-- get some metadata from the TEI header using the push paradigm -->
<xsl:text>\begin{itemize}</xsl:text>
<xsl:for-each select="//t:persName[ancestor::t:teiHeader]">
    <xsl:text>\item </xsl:text>
    <xsl:value-of select="." />
    <xsl:text>

    </xsl:text>
</xsl:for-each>
<xsl:text>\end{itemize}
\newpage</xsl:text>

        <!--  <xsl:apply-templates/> OR -->
        <xsl:apply-templates select="//t:text"/>
        <!-- just use the pull paradigm on the TEI body so you don't get a meaningless TEI header dump in your document -->

        <xsl:text>\end{document}</xsl:text>
    </xsl:template>

    <xsl:template match="t:head">
        <xsl:text>\section{</xsl:text><xsl:apply-templates/><xsl:text>} </xsl:text>
    </xsl:template>

    <xsl:template match="t:p">
        <xsl:apply-templates/>
        <xsl:text>

        </xsl:text>
    </xsl:template>

    <xsl:template match="t:hi">
        <xsl:text>\emph{</xsl:text><xsl:apply-templates/><xsl:text>} </xsl:text>
    </xsl:template>

    <xsl:template match="text()">
        <xsl:analyze-string select="." regex="([&amp;])|([_])|([$])">
            <xsl:matching-substring>
                <xsl:choose>
                    <xsl:when test="regex-group(1)">
                        <xsl:text>\&amp;</xsl:text>
                    </xsl:when>
                    <xsl:when test="regex-group(2)">
                        <xsl:text>\_</xsl:text>
                    </xsl:when>
                    <xsl:when test="regex-group(3)">
                        <xsl:text>\$</xsl:text>
                    </xsl:when>
                    <xsl:otherwise/>
                </xsl:choose>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="." />
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>

</xsl:stylesheet>

 

The XSLT declaration and the LaTeX preamble

Put the following after your XML declaration. This will ensure output is LaTeX-friendly.

 

<xsl:strip-space elements="*"/> <!-- for LaTeX -->
<xsl:output method="text" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>

 

\DeclareUnicodeCharacter{2060}{\nolinebreak} was added because LaTeX complained about an undefined character in some of my students XML data. Personally, I had never gotten this error before, so you might as well leave it out.

Creating environments

As we had just learnt some XSLT basics, I wanted the students to use at least one push and one pull paradigm type template. So the task was to process any element from the TEI header using the push paradigm and then a pull paradigm template for the body. To make this little template more efficient teaching-wise, I decided to introduce how to create a LaTeX environment using XSLT for the TEI Header / push paradigm and do at least one other command using the pull paradigm on the TEI body. Also this demonstrates as opposed to for the body.

So this next piece of code sets up an itemize environment for persons present in the header. In a “real” stylesheet, it would probably be more wise to check, using whether there is one potential element like that present and only paste the \begin and \end on that condition.

Also, as you might have noticed, all the LaTeX commands are inside . This looks a bit confusing at first but really isn’t. Just make sure you don’t create invalid XSLT by shuffling them around.

 

<xsl:text>\begin{itemize}</xsl:text>
<xsl:for-each select="//persName[ancestor::t:teiHeader]">
    <xsl:text>\item </xsl:text>
    <xsl:value-of select="." />
    <xsl:text>

    </xsl:text>
</xsl:for-each>
<xsl:text>\end{itemize}</xsl:text>

 

Pull paradigming emphasis

When creating simple commands using the pull paradigm, be sure that you don’t end up with too many “overlaps” since “simple” commands in LaTeX don’t take multiple paragraphs as arguments. If in doubt, always use environment and the global switches (like \bfseries). Since you are automating things, you always have to take into account that data might not always be marked-up in a way which makes sense to you. There can easily be linebreaks inside a single italic highlight. If this is the case in you data, better create an environment. For simple purposes, however, this is good enough:

 


<xsl:template match="t:hi"><xsl:text>
\emph{</xsl:text><xsl:apply-templates/><xsl:text>} <xsl:text></xsl:template>

 

With these commands (and genereally when transforming to LaTeX), you sometimes need to make sure you don’t involuntarily add spaces or lack space which will make the output hard to read and debug.

In this example, I made sure not to add any whitespace inside the template rule and also did not have Oxygen format or indent the XML to avoid these unwanted spaces.

And finally: Escaping entities

As you might remember, markup languages tend to use entities to escape certain characters. Bad thing is, LaTeX and XML use different entities. So we need to escape them. I know that the OxGarage standard stylesheet does this using the translate() function but I prefer to use since it’s less “messy” than a nested translate() construct.

Ah, and side info by the way: There is this standard stylesheet from the TEI consortium which might be of help if you are looking for inspiration. Since it is very generic, however, it might not be helpful if you are a newbie at both XSLT and LaTeX. The XSLT is pretty advanced and also the LaTeX probably uses some commands you might not be aware of.

 

    <xsl:template match="text()">
        <xsl:analyze-string select="." regex="([&amp;])|([_])|([$])">
            <xsl:matching-substring>
                <xsl:choose>
                    <xsl:when test="regex-group(1)">
                        <xsl:text>\&amp;</xsl:text>
                    </xsl:when>
                    <xsl:when test="regex-group(2)">
                        <xsl:text>\_</xsl:text>
                    </xsl:when>
                    <xsl:when test="regex-group(3)">
                        <xsl:text>\$</xsl:text>
                    </xsl:when>
                    <xsl:otherwise/>
                </xsl:choose>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="." />
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>

 

And that’s it. I hope this was useful to you.

Cheers,

the Ninja

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

A Humanities’ seminar paper with LaTeX – in 10 minutes

Don’t believe me when I claim you could write a whole seminar paper in 10 minutes? I wouldn’t either 😉 But I firmly believe you can learn how to write the next one in LaTeX in just ten minutes, so I prepared this pretty self-explanatory document. Everything is explained there, so I won’t ramble on about it here. The document is here on Overleaf. There you go.

Little side note, in case you are completely new to LaTeX. Like in the picture below, LaTeX has source code (on the left) and the compiled output PDF on the right. If you mess up the source code, there might not be any ouput. Using CTRL+S will cause the Overleaf editor to try and compile automatically. You can download the resulting PDF by clicking on the symbol beside the ‘recompile’ button. Overleaf also provides info on how to use Overleaf.

latex-seminar-paper

So, that’s it with a very short post for today. Watch out for the upcoming “(Why) Should I use LaTeX for my PhD thesis” post!

So long and thanks for all the fish!

The Ninja

 

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

The power of simplicity, or: How to use tutorials

This is just a quick post, telling you to use tutorials selectively. If you don’t have time, don’t burden yourself with the not-so-short intro to LaTeX or 30 min introductions. Jumpstart in 3 minutes and go.

This morning, I realized one thing: depending on what you want to do with LaTeX, you only need a very limited amount of commands. Even I use a very limited amout of commands for everyday tasks. Going through a whole tutorial might actually be a waste of time for you.

 

You only need 3-5 go-to commands

What you always need (and, for example, an Overleaf blank document already supplies): You will typically need the general document setup (minimal example), \newpage, \maketitle, \tableofcontents, and \sections and \emph{}.

For teaching documents, I will additionally need \textbf{boldface}, enumerate and itemize environments. Then maybe \href{http://latex-ninja.com}{links} (\usepackage{hyperref}), \texttt{typeface} for code or the verbatim environment. And, of course, I often use my cheatsheet template.

For writing scientific articles, I will need bibliographic citation (biblatex), mostly using \footcite{} and \footnote{}. Then maybe sometimes the quote environment for longer quotes. Then a Pandoc conversion to .docx (see the post on how to quit MS Word).

But that’s basically it. The more complicated stuff I use only when I have real typesetting needs or do something overly visual. That’s how I managed to use LaTeX for 5+ years without going any deeper.

The power of simplicity

What I want to say with this is: You don’t need to learn all the concepts to get started. You won’t be able to use all of them anyway. Only learn the ones you need right now to get going. Learn the rest as you go.

30 minute (or longer) introductions to LaTeX are great, but depending on your needs (especially if your a Humanities person who never uses any math or the like), you don’t need to go through complicated tutorials. Just starting  using LaTeX and add skills as you go.

LaTeX is supposed to have “a high learning curve” and take way more time than just using Word. People often say that if you’re not interested in typesetting technical stuff, there is no point in learning “complicated LaTeX”, but LaTeX is not complicated. Not unless you have complicated needs, then it is adequate. Especially if you’re a Humanities scholar – be happy that you can enjoy excellent typesetting without learning the more complicated technical parts of LaTeX. Once you’re used to the general gist, you can add the more fancy features without stress.

Don’t let listings of commands scare you away – you probaby won’t need them and, most importantly, you don’t need to remember them now. You probably don’t even need to know of their existence. If you have a problem, just type "latex how to [...]" in Google and you’ll most certainly find help. Or drop me a note, I’m always happy to help.

So, that’s all I wanted to say for now.

Cheers,

the LaTeX Ninja

 

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

How to quit MS Word for good

This post I want to dedicate to the pressing question of how to live without Word in the Word-filled environment of Academia where Word lurks behind every tree and jumps at you when you’re not paying attention.

Do you actually enjoy this eternal distraction of a non-working text editor? Well, I don’t. And even though it’s not actually a good tool (if you’re being honest with yourself, deep down in your heart, you know I’m right), it has infested the world (not only of Academia).

 

How the story begins…

At some point, now over a year ago, I decided that I wanted to quit MS Word once and for all. I had hoped to do that before but every single time, I had came up with about a million excuses why I just couldn’t. Probably kind of like you are now already preparing your counter arguments as to why that might work for me but it sure as hell is completely impossible for you. You can’t survive in your workplace without Word because everyone’s using it.

Like Tim Ferriss, I want to invite you reflect on this Mark Twain quote now and better yourself:

“Whenever you find yourself on the side of the majority, it is time to pause and reflect.” – Mark Twain

The impossibility of quitting Word? Rehab.

Think of this post as your rehab where you can get sober once and for all. And I’ll provide you with answers to a few key problems which you might encounter during the process to make sure you stay sane.

I got fed up with Word so much that at some point, I wanted to quit but wasn’t sure it would actually be possible to get rid of it for good. Everybody was using it. How was I going to communicate or collaborate with my Word-loving colleagues? But I had really had it with Word and it needed to go. Because, you know, Word really is like drugs – it’s not good for you but you keep using it. I needed to break the habit. And, believe it or not, I have lived a happy, Word-free life for over a year now.

Transitioning to full-time LaTeX

So as this blog is called “The LaTeX Ninja”, of course, I urge you to quit Word in favour of LaTeX. “But that will everything take forever”, you say. What if I need to take a quick note? Well, as you might remember from somewhere way back in the past you most certainly have some basic text editor or notepad tools already installed on your system. It’s just that you never use it. But isn’t that exactly for that purpose of taking quick notes? You can still use that. Or just make it a habit to always use LaTeX. I also started that habit a while ago (for documents where I want some visual structure, highlight something, make lists, etc.) and really, you learn those few commands by heart so fast. Just make a mini project to commit to taking all your notes with LaTeX for two days (where you preferably don’t have important meetings where it’s vital you can keep up with your note-taking).

So if you say this will slow you down, that’s a blatant lie. Taking your hands off the keyboard to take the mouse, select and click to make something bold definitely takes longer than just writing it. If you’re using keyboard shortcuts, congrats you’re an advanced user. So you don’t have an excuse why you can’t learn a text editor like VIM which provides some auto-completion for LaTeX. No more excuses.

A side-effect of transitioning to LaTeX completely will be accelerated learning of LaTeX, since you will be forced to look things up and learn new concepts regularly. So if your goal is to become an advanced LaTeX user, I can tell you one thing – your progress will be exceptionally slow if you never expose yourself to having to rely on LaTeX. If you always use Word, your LaTeX skills won’t get better at a steady pace.

Problem 1: I sometimes work on computers without LaTeX installed and no rights to install anything

Working on a computer that doesn’t have LaTeX? It’s horrifying, I know. Yes, it’s a disaster. I tend to get panic attacks and so on, but hey – thank God there’s Overleaf, the tool that allows you to compile LaTeX even from weird, Word-infested computers, if they only have internet.

Problem 2: But I need to see what my text will look like while writing.

No, actually you don’t. You’re just so used to Word or Word-style WYSIWYG editors that you don’t remember anything else. The tools we use shape how we think and work. With Word being a tool which suggests to its users that they are so apt at typesetting that they should do it. Info: No, you shouldn’t, unless you’re a qualified professional. So, if typesetting really isn’t your job, you totally don’t need to see what the typeset final output will look like. Just focus on the fucking content. That’s your job.

Like typewriters, or an actual notebook and a pen, LaTeX is just a different medium. You were ok using a pen, weren’t you? That’s a different medium too. When you transitioned from analogue notebook to MS Word, that was a transition, too. And you mastered it. If you’re old enough, you might remember typewriters. There you didn’t have much control over how your output looked like either. Other than instant-typesetting Word, typewriters required you to write out the manuscript by hand, on paper, so you wouldn’t screw up too many times when actually typing it out. That was a completely different style of working. It took more time and precision. You had to pause and reflect before acting. So maybe transitioning to a new way of doing things will make you more aware than just typing away in Word where you write on auto-pilot. If you’re someone who needs nice looking output: transition to LaTeX. If you’re a knowledge worker: Congratulations, your professional worth is not determined by how fast you create content but by how good it is. Using a tool that takes a little longer to type it out forces you to reflect more and will up your awareness. Win-win! Transition to LaTeX.

You don’t need Word. You’re just addicted to the Word way of life and I want you to quit and live a happier life in the long run – you’ll thank me later. Especially should you ever come to have some advanced typesetting needs. Like a 500 page PhD thesis in Archaeology with 2000 images. Or the honour of editing conference proceedings is bestowed upon you. Start learning the skills now, save time and tears in the future. Thank me later.

Problem 3: Everybody else uses Word – how will I be able to communicate?

The conversion routine, part 1: Pandoc

Just use a PanDoc conversion whenever you feel like sharing. It works as follows (and more info can be found in the PanDoc demos):

pandoc main.tex --smart --bibliography=literature.bib -S -o output.docx

This means that Pandoc will use your main .tex document as a source and pandoc-citeproc (the citation plugin) will use literature.bib as the bibliography file. -o means that output.docx will be the name of the output. However, please note that a) you have to install both pandoc and pandoc-citeproc for this to work and b) this is a very generic transformation. If you have custom commands or citation styles in your document, these elements will not be correct in the output. So if you already know you’ll have to hand in a document as .docx, just don’t do anything complicated. The citation might not come out the way you’ll need it but for a normal length paper, this doesn’t take more than 10 minutes to correct (and you’d have to check your citations before handing it in anyway – at least I assume you, as a good scientist, hopefully, always do that…). Use search and replace wisely. If you need to hand in author-year style, the big changes to be made are going to be only in the bibliography anyway.

Part 2: Manipulating and sharing documents with GoogleDocs (version control included)

Then, once this is done, you are just one more final step away from the bliss of Word-free life: Sell your soul to Google, so you can use Google Docs. Now, open a new document and import output.docx. Now you can do all your editing (without Libre Office messing everything with their .odts) and download in the requested file format (probably .docx). Also, in case you didn’t know, GoogleDocs has a footnote plugin you have to add manually (Add-ons > Get Add-ons > Footnote Style). Once this is done, you can mark any footnote and say something like “apply this style to all footnotes”. This will come in very useful because GoogleDocs don’t automatically support batch editing multiple footnotes at once.

Plus, the benefit of the “comment”, “share” and “track changes” (version control) features GoogleDocs provides. This even allows you to collaborate with version control while multiple contributors work on the same document simultaneously. No more “Document-1”, “Document-1-1”, “Document-1-correction”, “Document-1-final”, “Document-1-final-revision”. Who the hell is supposed to remeber which one is the current version? Get version control. Overleaf also has version control by the way. You can use any version control tool you want when working with LaTeX. Version control might still be a strange and scary topic if you’re a non-technical person. But it’s really no big deal and I’ll explain it in some other post. Also, for tools I suggested, like GoogleDoc or Overleaf, you don’t need to know shit. Thank God!

You still think you can’t live without Word in your life? If I managed to quit Word for good, so can you. And just so you know: I never regretted it for a second. Now I can’t imagine how people even live with Word in their lives.

Best,

your LaTeX Ninja

 

PS: If you think using LaTeX would slow you down, see this post on Typing fast in LaTeX.

 

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

Fancy Headers and final Footers in LaTeX

This post explains advanced uses of headers and footers. The template changes between two fancy pagestyles and provides a TikZ based header and a – alsoTikZ based – final footer which only appears on the very last page of the document (which LaTeX will determine on its own without you setting it explicitly).

 

[Markdown is kind of broken in this post. Parts of it were repaired but other parts seem stubbornly broken (and break over and over again), so I decided that it will be ok to stay like this. If you’re interested in the information – it’s all here. It doesn’t look so good but that you should be able to survive 😉 ]

template-headfoot

This post is not intended for beginners who just want to make simple use of the basic fancyhdr features. A great explanation of these can be found in the ShareLaTeX tutorial (see “Resources” section below).

So if you don’t care to read the following (long) explanation of these advanced header / footer uses, just use my Overleaf template and come back here if you want to customize something to get information you need. All the facts are here.

You can find it here.  It’s a view-only share link to the template I created but I can’t publish it as a template via Overleafv2, so have fun with the link (hopefully this will be possible later). Just copy it as your own project or something.

The code can be found in full in the Overleaf template and has extensive comments. I will, however, explain all the snippets even more in detail in this post, so you can understand what I did and why I did it. Especially because the code to create this might be overwhelming to you in whole if you haven’t done a lot of advanced LaTeX customizing so far.

General settings for our document

This is the preamble, not a lot to explain here so far, so just the code:

 

\documentclass[10pt, a4paper]{article}
\usepackage[utf8x]{inputenx}

% Page Settings
%--------------------------------------------------------------------
\usepackage{geometry} % Allows the configuration of document margins
\geometry{includeheadfoot,a4paper, textwidth=0.87\paperwidth, textheight=0.8\paperheight}
\usepackage[onehalfspacing]{setspace}

\usepackage{lipsum} % provides lorem ipsum for testing

% Font Settings
%-------------------------------------------------------------------
\usepackage{lmodern} % http://www.tug.dk/FontCatalogue/latinmodernroman/
\usepackage[thin]{raleway} % different font for the TikZ header
\usepackage{url}

 

 

And some further settings here:

 

%\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
% Settings for Fancy Headers and Footers
%-------------------------------------------------------------------

% Settings for TikZ Headers with coloured background
%-------------------------------------------------------------------
\usepackage{atveryend}
\usepackage{lastpage}

\usepackage[usenames, dvipsnames]{color} % https://de.sharelatex.com/learn/Using_colours_in_LaTeX#!#Reference_guide z.B. \color{RubineRed} - use ColorNames
\usepackage[dvipsnames]{xcolor}
\definecolor{CornflowerBlue}{RGB}{100,149,237} %#6495ed (HTML) - define your own colors
% pick some from here: http://latexcolor.com/

 

 

Setting header and footer with the fancyhdr package

Why is this chapter here? Didn’t I say I was not going to do the basic fancyhdr explanation? Yes, I did indeed. This is why you’ll just get the code snippet with its comments from Overleaf. What I did here is no sorcery and can be understood from the ShareLaTeX tutorial (see “Resources” below). I find that ShareLaTex generally does a great job in explaining the stuff you really need, even as an advanced user. It gives an overview on the most common packages without being as confusing as their package documentations. Definitely worth checking! ( https://www.sharelatex.com/learn )

 

% Settings for "normal" headers and footers
%-------------------------------------------------------------------
\usepackage{fancyhdr} % http://mirror.easyname.at/ctan/macros/latex/contrib/fancyhdr/fancyhdr.pdf
\pagestyle{fancy}

\fancypagestyle{fancy1}{
\fancyhf{} % clear space at the header and footer so the fancy headers / footers can be placed
%-------------------------------------------------------------------
\renewcommand{\headrulewidth}{2pt} % set a head rule of 2pt thickness
%\renewcommand{\footrulewidth}{1pt} % same would be possible if you wanted a footer rule
%-------------------------------------------------------------------

% things you might want to access here: \thesection \thechapter \chaptername \sectionmark \rightmark \leftmark
% check this for further info: https://en.wikibooks.org/wiki/LaTeX/Customizing_Page_Headers_and_Footers

% puts a small logo on the right side of the HEADER - same goes for the \lhead:
\rhead{\includegraphics[width=0.04\textwidth]{logo.jpg}}
\lhead{\footnotesize\textbf{Example citation:} \textsc{Author-Lastname}, Surname: ``Article title'', in: \textsc{Editor} (ed.): \emph{booktitle}, NY 2018. {\textsc{Link:}} \protect\url{http://mylink.com}{ } \lbrack{}\today\rbrack{}.}
% you could you \chead to access the center as well

%-------------------------------------------------------------------
% defines all the FOOTER settings. But in this case, they are conditional: We check if we're on the last page and only print it, if we're not.
\rfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else\includegraphics[width=0.1\textwidth]{logo.jpg}\fi}
\lfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else{\scriptsize your custom footer text goes here}\fi}

% add the page count in the middle: \thepage gives you the current page, \pageref{LastPage} the total
\cfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else\thepage/\pageref{LastPage}\fi}
}

 

 

If the part where the if conditions turn up in the footer settings confuse you, don’t worry. I will explain this in the final footer part.

header3

Creating the final footer

Using hooks to find the last page of a document

Finding the last page of a document in LaTeX is not as trivial as it might seem. Sometimes, you might succeed just using \AtEndDocument. But this will only work if the contents of the last page have not been shipped out before LaTeX realizes it needs to check if it’s the last page. Sometimes, this will work just fine. Other times, all the content is already printed once you reach this point. This is why we need the atveryend package which will help us find the real last page of our document by setting some more page hooks after the \AtEndDocument is executed and after the last shipout is done.

In our example, we trigger this behaviour in the fancyhdr part where we check if we’re on the last page. Then, we don’t want fancyhdr to print the footer. Because now, our footer background will executed: That’s right – our final footer is actually a TikZ-based background setting which is only applied to the last page where we disabled the fancyhdr footer.

Having used \usepackage[pages=some]{background}, we could also invoke this background manually anywhere we want like this: \BgThispage. This, however, I found a bit tedious. I wanted to automatically create LaTeX output from XML files using XSLT transformation. So, of course, I wouldn’t be able to manually add \BgThispage at every document’s last page. First of all, because it’s tedious and then, how do you even know where this is if you don’t typeset all the pagebreaks by hand? So I came up with the solution presented here.

(I am not 100% sure, however, if this is the most elegant or failsafe solution possible – always happy to get your feedback!)

 

%\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
%-------------------------------------------------------------------
% packages for the custom header and footer
\usepackage{tikz}
\usetikzlibrary{shapes.misc,positioning,backgrounds}

%-------------------------------------------------------------------
% different last page footer
\usepackage[pages=some]{background}
\usepackage{tikzpagenodes}
\usepackage{pageslts,refcount}

%-------------------------------------------------------------------
% credit: https://tex.stackexchange.com/questions/120773/footer-on-last-page
\newcommand{\footercustomlastpage}[3]{% here a command is set
\backgroundsetup{% from the background package
scale=1,angle=0,color=black,%
contents={% contents then contain basically the same TikZ picture as I use for the header
\tikz[remember picture,overlay]{%
\fill[gray!70,ultra thick]%
([yshift=120pt]current page.south west)%
rectangle%
(current page.south east);%
\node[anchor=north west,inner sep=0pt,text width=.75\paperwidth,align=left] at ([yshift=15pt,xshift=50pt]current page.south west|-current page text area.south west) {#1};%
\node[anchor=north,inner sep=0pt,text width=.3\paperwidth,align=right] at ([yshift=-5pt,xshift=90pt]current page text area.south) {#2};%
\node[anchor=north east,inner sep=0pt,text width=.3\paperwidth,align=right] at ([yshift=-5pt,xshift=-30pt]current page.south east|-current page text area.south east) {#3};%
}}}%
}

%-------------------------------------------------------------------
% I made a command for this, so you can put the above in an external file
% and only keep the actual contents of the footer in this main file
% making a new command would, of course, not been necessary
%-------------------------------------------------------------------
\footercustomlastpage{
\begin{minipage}[t]{0.67\textwidth}
{\huge Jack Sparrow image credit: Walt Disney. Thanks, mate!}
\scriptsize\lipsum[56]
\end{minipage}
}{
\includegraphics[width=0.5\textwidth]{jack.jpg}
}{
\includegraphics[width=0.4\textwidth]{logo.jpg}
}

%-------------------------------------------------------------------
%--------------------------------------------------------------------------------- End footer placement
\usepackage{everypage}
% here we determine that the footer (which really is a background constisting of TikZ picture
%will be printed on the very last page only
\AddEverypageHook{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\clearpage\BgThispage\else\fi}
%\AfterEndDocument{\clearpage\vfill\fancyhf{}\cfoot{}\rfoot{}\lfoot{}\BgThispage}

 

 

header4

A possible problem with this solution might be that I never use \thispagestyle{empty}, so your content could possibly overflow into the footer, if the last page is very full. Usually it doesn’t do that and if it does, it can usually be avoided by rearranging the last few pages a little bit. When you don’t do automated transformations like I did, this shouldn’t bother you much. Also, with the geometry settings I used, I found that it wasn’t much of a problem and only a tiny bit visible when I, for example, excessively used footnotes on the last page.

If you want to absolutely ensure that your header and footer are cleared, you have to use  \thispagestyle{empty}, which will overwrite  \pagestyle{fancy} we set at the beginng, but for the current page only. Mind you though, this will not only affect the footer section but cause you to have no header as well. This is why I don’t do it and accept some minor overflow as the tradeoff.

\thispagestyle{plain} will remove the header and footer for one page but at least will keep the page numbering in the footer, by the way. Non-fancy, LaTeX automatically created centered page numbering, that is. So no “page 3 of 3”. Just “3”.

The header using a TikZ background

The header command I created resembles the footer in the way that it is also a TikZ background, only this time it’s not set to be transparent (like above) and it’s at the top of the page. This time, I also want to be able to use this for every page I want, whenever I want. (We could configure it as a replacement / version of \maketitle which some people do in custom CV templates, but I prefer it this way. It keeps me in control of my document.) While the footer just has three textareas you can fill as you please, the header has one circle for a picture and three spots for text. It’s a header I configured for a CV template, so feel free to make your own version of this header command to fit your needs.

 

%-------------------------------------------------------------------
% inspired by: https://www.sharelatex.com/templates/cv-or-resume/fancy-cv
\newcommand{\header}[7]{
\thispagestyle{header}
\tikz[remember picture,overlay] {%
\node[rectangle, fill=#5, anchor=north, minimum width=\paperwidth, minimum height=5cm](header) at (current page.north){};%
\node[left=#7 of header.north, anchor=east](name) at (header.east) {\fontfamily{\sfdefault}\selectfont #2};%
\node[anchor=south east](degree) at (name.north east) {\fontfamily{\sfdefault}\selectfont\flushright #1};%
\node[anchor=north east](descr) at (name.south east) {\fontfamily{\sfdefault}\selectfont #3};%
\node[right=#6 of header.west, anchor=west](picture) at (header.west) {};%
\draw[path picture={\node[anchor=center] at (path picture bounding box.center){\includegraphics[height=4.3cm]{#4}} ;}] (picture) circle (2) ;}%
\vspace{1.5cm}%
}
%-------------------------------------------------------------------

 

For this command to work, I had to ensure there was more than one fancy pagestyle available because we don’t want a normal header displayed when using this special one. Also, the special header needs some tweaking with geometry etc. because it’s larger and in the fancyhdr package, we have the problem that the footer will disappear when \headheight becomes too large. In our case, large means 5cm – that’s too large for fancyhdr.

So we set a new geometry locally for the page the header command is used on and restore it afterwards. We also activate the pagestyle for these pages only by using \thispagestyle{header} instead of \pagestyle{header}.

 

\usepackage{afterpage}
\fancypagestyle{header}{
\newgeometry{includeheadfoot,a4paper, textwidth=0.87\paperwidth, textheight=0.7\paperheight, top=3cm, headheight=0cm, headsep=0cm}

\fancyhf{} % clear space at the header and footer again
%-------------------------------------------------------------------
\renewcommand{\headrulewidth}{0pt} % get rid of the headrule

%-------------------------------------------------------------------
% defines all the FOOTER settings to work as above.
% We still check if we're on the last page and only print it, if we're not.
\rfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else\includegraphics[width=0.1\textwidth]{logo.jpg}\fi}
\lfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else{\scriptsize your custom footer text goes here}\fi}

% add the page count in the middle: \thepage gives you the current page, \pageref{LastPage} the total
\cfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else\thepage/\pageref{LastPage}\fi}
\afterpage{\restoregeometry}
}

 

Styling the header

\fontfamily{\sfdefault}\selectfont selects the raleway font we loaded in the preamble. This is just because I thought it looked good. Do whatever you want.

The command takes a background colour as one argument, the three textareas, the image location and two centimenter values for the placement of the image circle and the texts in the header. The first three arguments are the text areas.

By the way (did I mention this already?), this header command comes from a custom CV template I created. I will show it to you as soon as I’m fully happy with it. But so far, suffice it to say that it was inspired by the friggeri-cv class (as always, see “Resources” for links).

 

Jumpstarting: Learn LaTeX in 3 minutes

Inspired by the learn x in y minutes tutorials, here comes my contribution to starting LaTeX quickly. If you want to jumpstart learning LaTeX, open your Overleaf account (or get one, they just require your email, no other info, takes 30 seconds) and open a blank or example project.

A blank project will give you the following output:


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

\title{\LaTeX in 3 min}
\author{Your name}
\date{January 2019}

\begin{document}
\maketitle

\section{Introduction}

\end{document}

You can now start typing text. Wherever you want, but for now, preferably below \section{Introduction} and in between \begin{document} and \end{document}.
The stuff before is the settings which don't interest you just yet. There you can see fields for title and author which \maketitle uses to make a title. This is what you can use to generate a title page later on.

Now type a sentence below \section{Introduction}, then hit space twice. Write another test sentence. Hit space twice and write \subsection{test}.

Now add \tableofcontents below \maketitle. Cool, huh?

\textit{makes text italic}, a similar but different effect is achieved with \emph{which highlights}. Make some \textbf{bold} statements and don't forget the ``quotes''\newpage will cause a manual pagebreak. Now copy this sentence into your test document.

Add \usepackage{hyperref} below the other \usepackage. Then add \href{http://latex-ninja.com}{\LaTeX{} Ninja} in the text.

With that, I think my 3 minutes are more than over and you are ready to go and do some exploring on your own.

Yours,

the LaTeX Ninja

PS: You might also be interested in the the Visual FAQ, a document showing things you might want to achieve with LaTeX which you can just click and it will redirect you to a TeX-FAQ tutorial where the chosen thing is explained. This is great if you want to get going as quickly as possible and learn as you go. Which you will have to or I won't keep my promise of an intro to LaTeX in 3 minutes 😉

PPS: The goal of this tutorial was not to give the illusion one could learn complete LaTeX in 3 minutes but rather to give you a quick "jumpstart" into LaTeX. In learning new things, people often don't try things out because the initial hurdle is too big. This post, on the opposite, is supposed to get you actively using LaTeX straightaway.

 

Resources

Visual FAQ