1

I am getting familiar with book writing in LaTeX now and I am trying to create macros (editted) for sections with different layouts, for example

  • Tips
  • Memories
  • Funny facts

Every time I use one of the layouts, I need it to automatically incorporate a template for, say, a "Tip", with maybe a different title, and when I write a "funny fact", I need it to invoke another template.

How is this achievable in LaTeX? What commands/macros do I need to use?

1
  • 1
    You should take a look at the titlesec package. It defines two main commands: \ titleformat` and titlespacing to cutomise the layout of chapters, sections, &c.
    – Bernard
    Aug 4 '16 at 11:17
3

What you are looing for are macros, commands and environments. They are not called templates in the LaTeX world.

matevaMacros

\documentclass{book}
\usepackage{blindtext}
\usepackage{tcolorbox}
\newenvironment{tip}{{\par\large\centering TIP \par}}{\par}
\newenvironment{funny}[1]{{\bigbreak\noindent\color{blue!20!orange}\large Fun fact: #1  \par}\noindent\ignorespaces}{\par}
\newtcolorbox{memory}[1]{title=#1}
\begin{document}
\begin{tip}
    \blindtext
\end{tip}
\blindtext
\begin{memory}{The night I met her}
    \blindtext
\end{memory}
\begin{funny}{Wombats are cute}
    \blindtext
\end{funny}
\end{document}

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.