Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to insert/embed symbols/images behind a heading.

Do you know, if that can be done?

share|improve this question
2  
Maybe this post could give you some ideas. Gonzalo Medina used tcolorbox to put a picture behind a tabular environment. I am not sure how you would extrapolate this to section headings (that is get an image behind the heading). tex.stackexchange.com/questions/128231/… –  dustin Aug 15 '13 at 20:36
1  
@LaRiFaRi I think the user wants the heading and then a picture behind the text as in a water mark type look. –  dustin Aug 15 '13 at 20:37
    
Does the link I posted capture the idea but in a different context then? –  dustin Aug 15 '13 at 20:40
add comment

1 Answer 1

up vote 7 down vote accepted

A possible solution using titlesec and tcolorbox (make the adjustments that best suit your needs):

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\tcbset{
bgtable/.style={
freelance,
frame code={}
center title,
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
watermark graphics=bricks.jpeg,
watermark stretch=1.00,
watermark opacity=0.7,
arc=0pt,
outer arc=0pt,
nobeforeafter}
}

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}
  {%
    \setbox0=\hbox{\Large\bfseries\thesection\hspace{1em}}%
    \begin{tcolorbox}[bgtable]
      \thesection\hspace{1em}\hangindent\wd0\strut#1\strut%
    \end{tcolorbox}%
  }
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries}{}{0em}
  {%
    \begin{tcolorbox}[bgtable]
      \strut#1\strut
    \end{tcolorbox}%
  }
\titlespacing*{\section}
  {0pt}{4.5ex plus 1ex minus .2ex}{1ex plus .2ex}

\begin{document}

\section{Test numbered section}
\lipsum[4]
\section*{Test unnumbered section}
\lipsum[4]
\section{Test numbered section with a long title; in fact, it spans two lines}
\lipsum[4]

\end{document}

enter image description here

My example only deals with \section and \section*, but the same idea can be easily adapted to other sectional units.

In the comments, it has been required to add an image to the left of the titles; in this case, there's no need for the tcolorbox package and one can use \llap and some boxes:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}
\usepackage{lipsum}

\newcommand\SecImage{%
\llap{\makebox[3em][l]{%
  \raisebox{-.65\totalheight}[0pt][0pt]{%
    \includegraphics[width=2em]{example-grid-100x100pt}%
    }%
  }%
}%
}

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}
  {%
    \setbox0=\hbox{\Large\bfseries\thesection\hspace{1em}}%
    \SecImage\thesection\hspace{1em}\hangindent\wd0\strut#1\strut%
  }
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries}{}{0em}
  {\SecImage#1}

\begin{document}

\section{Test numbered section}
\lipsum[4]
\section*{Test unnumbered section}
\lipsum[4]
\section{Test numbered section with a long title; in fact, it spans two lines}
\lipsum[4]

\end{document}

enter image description here

share|improve this answer
1  
I figured you would answer this question. –  dustin Aug 15 '13 at 23:04
    
@dustin yes; the code in the other answer was almost ready to transfer here :-) –  Gonzalo Medina Aug 15 '13 at 23:06
    
@Stefan no; no known conflicts. As long as you have an up-dated LaTeX system, my code works as expected. Some questions for you: Compile my example code as is (replacing bricks.jpeg with one of your own images) Do you get errors? If not, what exactly is the error message you get when incorporating my code into your document? –  Gonzalo Medina Aug 16 '13 at 16:42
    
@Stefan surely yes, but I don't quite understand what you want. Where exactly should the image appear? –  Gonzalo Medina Aug 20 '13 at 17:49
    
@Stefan so the image should start a little left from the left margin and span the whole text width area, as in my answer (but starting a little to the left)? –  Gonzalo Medina Aug 20 '13 at 21:03
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.