# Custom subsection title with image

I would love to use custom subsection title with image in my TeX project, can anyone help me how to do it? I don't need it exactly the same just the layout is important. Thanks a lot!

• Welcome! Are you aware of the titlesec package? – user121799 Feb 23 '19 at 20:12
• thank you, no I have very little experience with TeX unfortunately I have to use it for my project. So you suggest me to learn titlesec package and with it I will be able to produce this title? – klememi Feb 23 '19 at 20:19
• It was more the question if you are aware of it. I guess you could more or less use e.g. this answer as a basis for a solution. And if you have problems, you have a code that you could use for a question here. (Usually questions involve some code that shows what you have tried.) – user121799 Feb 23 '19 at 20:23

As mentioned in the comments, titlesec is the way to go. If you want to keep the subsection number and title, try

\documentclass{article}
\usepackage{graphicx}
\usepackage{titlesec}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\includegraphics{app.png}\hspace{0.5em}\thesubsection}{0.5em}{}
\begin{document}
\section{First section}
\subsection{First Subsection}
\end{document}


where app.png is the image of your app (if this image is too large, use the width= or scale= option of \includegraphics):

If you want to remove the subsection number from the title, remove \hspace{0.5em}\thesubsection from the \titleformat command, while if you want to remove the subsection title as well, load the titlesec package with the explicit option:

\usepackage{titlesec}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\includegraphics{app.png}}{0.5em}{}


And/or

\usepackage[explicit]{titlesec} % No subsection title unless explicitly included in \titleformat command
\titleformat{\subsection}
{\normalfont\large\bfseries}{\includegraphics{app.png}\hspace{0.5em}\thesubsection}{0.5em}{}



Comparison:

And/or

Similar could of course be done for the \section command.

Extra (see comments): You can add your own subection (or section) command to use a different image for different subsections. Using

\newcommand\mysubsection[3]{% #1: Image file (e.g. app.png), #2: Image scale, #3: Subsection title
\titleformat{\subsection}
{\normalfont\large\bfseries}{\includegraphics[scale=#2]{#1}\hspace{0.5em}\thesubsection}{0.5em}{}
\subsection{#3}
}


The call

\mysubsection{example-image-a}{0.4}{Subsection title}


produces (following on from the previous examples)

• thanks! One important note: is it possible to add parameter to section title? To make app icon variable. Something like \section{App name}{appicon} – klememi Feb 24 '19 at 9:35
• Yes, very easily - I'll add a small bit onto my answer for you – Pippip19 Feb 24 '19 at 16:07