3

I used the solution given at https://tex.stackexchange.com/a/34292/77602. But I am not getting the titles of the sections. As it's an article with no chapters, I deleted the chapter stuff. So it's

\documentclass[]{article}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage[table]{xcolor}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\newcommand\titlebar{%
    \tikz[baseline,trim left=3em,trim right=3cm] {
        \fill [cyan!25] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
        \node [
        fill=cyan!60!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.5ex] at (3cm,0) {
            \textbf{\thesection}
        };
    }%
}
\titleformat{\section}{\huge}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\Roman{section}}
\begin{document}

\section{Introduction}
\lipsum[1-2]
\end{document}

I am getting this:

enter image description here

  • 1
    Welcome to TeX.SX! Can you make the code into a minimal compilable example (starting from \documentclass up to \end{document}) that shows the issue? – egreg May 5 '15 at 23:40
  • It should work as a standalone code now. – Zack Fair May 6 '15 at 8:19
  • Is there also a way to make the right corners of the light rectangle rounded? – Zack Fair May 6 '15 at 8:29
  • Remove the explicit option. – egreg May 6 '15 at 8:33
1

Just remove the explicit option:

\documentclass[]{article}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[table]{xcolor}
\usepackage{tikz}\usetikzlibrary{shapes.misc}

\newcommand\titlebar{%
    \tikz[baseline,trim left=3em,trim right=3cm] {
        \fill [cyan!25] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
        \node [
        fill=cyan!60!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.5ex] at (3cm,0) {
            \textbf{\thesection}
        };
    }%
}
\titleformat{\section}{\huge}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\Roman{section}}

\begin{document}

\section{Introduction}
\lipsum[1-2]
\end{document}

enter image description here

Or keep the option and use

\titleformat{\section}{\huge}{\titlebar}{0.1cm}{#1}

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.