4

I have to insert an image a begin of every \section and \subsection using those LaTeX commands.

I have tried this:

\renewcommand{\@seccntformat}[1]{\mbox{\includegraphics{FigureFISSE/IconaT1.eps}\quad\mbox{\csname the#1\endcsname}\hspace{0.5em}}}

but typsetting the following error appears:

32: Argument of \@sect has an extra }.
<inserted text> 
                \par 
<to be read again> 
                   }
\@sect ...tected@edef \@svsec {\@seccntformat {#1}
                                                  \relax }\fi \@tempskipa #5...
l.32 ...ùòlkz xùl<k xùòlk<zxùlòk <ùòzlxk <ùòlxzk }
\documentclass{book}
\makeatletter
\renewcommand{\@seccntformat}[1]{\mbox{\includegraphics{FigureFISSE/IconaT1.eps}\quad\mbox{\csname the#1\endcsname}\hspace{0.5em}}}
\makeatother


\begin{document}

\chapter{Prova titolo}



Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo 
\section{Titolo sezione lòk xùl<kùxzlk òs àòsk fòskf àksò fdjks<ùòlxk ù<òlxk <ùòlkz xùl<k xùòlk<zxùlòk <ùòzlxk <ùòlxzk }
Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo 

\subsection{Titolo 2}
Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo 
Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo 

\end{document}

enter image description here

  • 1
    Make a complete example that can be used for tests. – Ulrike Fischer Mar 6 '17 at 17:00
  • \documentclass{book} \makeatletter \renewcommand{\@seccntformat}[1]{\mbox{\includegraphics{FigureFISSE/IconaT1.eps}\quad\mbox{\csname the#1\endcsname}\hspace{0.5em}}} \makeatother \begin{document} \chapter{Prova titolo} Testo testo TTesto testo Testo testo \section{Titolo sezione lòk xùl<kùxzlk òs àòsk fòskf àksò fdjks<ùòlxk ù<òlxk <ùòlkz xùl<k xùòlk<zxùlòk <ùòzlxk <ùòlxzk } Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo \subsection{Titolo 2} Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo \end{document} – Bruno Guizzon Mar 6 '17 at 18:02
  • Don't add examples as comments. Edit your question. And use a graphic that is not local, e.g. one from the mwe package. – Ulrike Fischer Mar 6 '17 at 18:03
  • I have added an image of one page showing what I need. Sorry, but I don't know how to attach the LaTex document – Bruno Guizzon Mar 6 '17 at 18:34
  • Your document doesn't load the graphicx package. Beside this: try \protect\includegraphics. – Ulrike Fischer Mar 6 '17 at 18:37
1

welcome to LaTeX.sx.

I think that you need the package named titlesec, it lets you customize any heading, in this example I changed a section style.

\documentclass[a4paper]{article}
\usepackage{titlesec,graphicx}

\titleformat{\section}
{\LARGE\bfseries}
{\includegraphics{FigureFISSE/IconaT1.eps}\quad \thesection}{1em}{}
\titleformat{\subsection}
{\Large\bfseries}
{\includegraphics{FigureFISSE/IconaT1.eps}\quad \thesubsection}{1em}{}

\begin{document}

\section{Introduction}

Some nice text.

\end{document}

You can find this in the manual page of the titlesec package, section 9.1 and 9.2. Just google it and you will find, or search on CTAN. I hope this helps.

  • Nice answer, but perhaps you should recast it in a form that is more readily compileable and presents all the changes, such as \documentclass[a4paper]{article} \usepackage{titlesec,graphicx} \titleformat{\section} {\LARGE\bfseries} {\includegraphics[width=1cm]{example-image-A}\quad \thesection}{1em}{} \titleformat{\subsection} {\Large\bfseries} {\includegraphics[width=1cm]{example-image}\quad \thesubsection}{1em}{} \begin{document} \section{Introduction} Some nice text. \subsection{Introduction} Some nice text. \end{document} – Steven B. Segletes Apr 7 '17 at 12:40
1

You're just forgetting \protect:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \protect\includegraphics[height=1.5ex]{example-image}\quad
  \csname the#1\endcsname\enspace
}
\makeatother


\begin{document}

\chapter{Prova titolo}

Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo

\section{Titolo sezione abbastanza lungo per andare a capo, potrebbe bastare}

Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo

\subsection{Titolo 2}
Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo
Testo testo Testo testo Testo testo Testo testo Testo testo Testo testo

\end{document}

enter image description here

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.