我使用了https://tex.stackexchange.com/a/34292/77602。但我没有得到章节的标题。由于它article
没有章节,我删除了章节内容。所以它是
\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}
我得到这个:
答案1
只需删除该explicit
选项:
\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}
或者保留选项并使用
\titleformat{\section}{\huge}{\titlebar}{0.1cm}{#1}