Text FormattingMake custom title

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Hermano
Posts: 14
Joined: Wed Apr 06, 2011 9:10 pm

Make custom title

Post by Hermano »

Dear all,

This is maybe a stupid question but I can not find how to define a preamble for my own (custom) title "\boldtitle". I can not use \maketitle as this gives me errors. It will be used as a sort of section but without numbering.

Code: Select all

\newcommand\boldtitle{?????}

\begin{document}

\boldtitle{[b]This is my title[/b]}

\end{document}
I want the title in bold that is left aligned an that has a defined white space before and after.

Thanks!
Last edited by cgnieder on Thu May 16, 2013 11:34 am, edited 1 time in total.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Make custom title

Post by cgnieder »

Hermano wrote:This is maybe a stupid question but I can not find how to define a preamble for my own (custom) title "\boldtitle". I can not use \maketitle as this gives me errors. It will be used as a sort of section but without numbering.
I don't really understand: do you want to customize the title that is made by \title, \author and \maketitle or do you want an unnumbered section (\section*{I'm not numbered})?

Regards
site moderator & package author
Hermano
Posts: 14
Joined: Wed Apr 06, 2011 9:10 pm

Make custom title

Post by Hermano »

I don't want to customize the title made by \title etc.
I want to create my own "title/heading" for a section which is not numbered and also not in the table of contents.

I can make it easily like:

Code: Select all

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.  \\

\noindent{\textbf{This is my title}} \\

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
But as I will use this format for a "title" many times, I want to create a preamble named "\boldtitle" such it looks like:

Code: Select all

\boldtitle{This is my title}
In this preamable, I want to define the spacings before and after the title, bold text, not numbered, left aligned and not in taken into account for the table of contents.
Last edited by cgnieder on Thu May 16, 2013 1:10 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Make custom title

Post by cgnieder »

Hermano wrote:I want to create my own "title/heading" for a section which is not numbered and also not in the table of contents.
There's already a command for this: the starred version of \section:

Code: Select all

\section*{Unnumbered section that will not appear in the ToC}
BTW: you shouldn't use \\ to terminate a paragraph. An empty line in the source suffices. \\ does not terminate a paragraph, anyway, but ends a line, which is a different thing.

Regards
site moderator & package author
Hermano
Posts: 14
Joined: Wed Apr 06, 2011 9:10 pm

Make custom title

Post by Hermano »

Dear cgnieder,

Thanks for the answer!
However, using \section*{} will make the fontsize bigger than the rest of my text. Is there a way to specify the size once for whole my document for the \section*{} command in such a way it doesn't influence the fontsize of the \section{} command?
Last edited by cgnieder on Thu May 16, 2013 6:10 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Make custom title

Post by cgnieder »

You could adapt the definition of \section from article.cls. The code below defines a macro \mycustomhead which works exactly like \section except that it uses \normalsize instead of \large. I also defined a second command \myhead that simply calls the starred variant of \mycustomhead in order to get an unnumbered heading without entry in the ToC:

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}

\makeatletter
\newcommand\mycustomhead{%
  \@startsection{section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\normalfont\normalsize\bfseries}}
\newcommand\myhead[1]{\mycustomhead*{#1}}
\makeatother

\usepackage{lipsum}% dummy text

\begin{document}

\section{test}
\lipsum[1]

\myhead{custom head}
\lipsum[1]

\end{document}
Regards
site moderator & package author
Hermano
Posts: 14
Joined: Wed Apr 06, 2011 9:10 pm

Re: Make custom title

Post by Hermano »

Thanks cgnieder for your clear answer! This solved mu problem!

Thanks
Post Reply