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

Zack Fair
  • 471

1 Answers1

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}
egreg
  • 1,121,712