修改部分样式

修改部分样式
\documentclass[12pt]{book}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usetikzlibrary{shapes.misc,arrows}
\newcommand\titlebar{%
\tikz[baseline,trim left=0.5cm,trim right=2.5cm] {%
    \node [
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (a) at (2.5cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (a.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (a.east) |- (\textwidth+3cm,-0.75ex);
}
}

\newcommand\subtitlebar{%
\tikz[baseline,trim left=1cm,trim right=3.05cm] {%
    \node[
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (b) at (3.05cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (b.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (b.east) |- (\textwidth+2cm,-0.75ex);
}%
}

\titleformat{\subsection}{\normalfont\sf}{\subtitlebar}{0.2cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\subsection}{-2cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\subsection,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesubsection}{\arabic{subsection}}


\titleformat{\section}{\large\sf}{\titlebar}{0.25cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{-2.15cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\section,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesection}{\arabic{section}}
\begin{document}
\chapter{This is a test}
\section{Section}
\lipsum[4-5]
\subsection{Subsection}
\lipsum[9]
\end{document}

此代码生成如下部分样式:如何删除线条(红线)。并增加部分名称的字体大小并更改字体大小

在此处输入图片描述

答案1

移除\titlebar\subtitlebar调整\titleformat间距。

对于部分内容,请将当前定义从

\titleformat{\section}{\large\sf}{\titlebar}{0.25cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{-2.15cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\titleformat{\section}{\LARGE\sffamily}{}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

而不要\LARGE使用任何其他字体大小开关,甚至\fontsize{}{}\selectfont

各个小节也需要进行类似的修改。

一个完整的示例,使用您的代码并根据建议进行修改:

\documentclass[12pt]{book}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usetikzlibrary{shapes.misc,arrows}
\newcommand\titlebar{%
\tikz[baseline,trim left=0.5cm,trim right=2.5cm] {%
    \node [
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (a) at (2.5cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (a.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (a.east) |- (\textwidth+3cm,-0.75ex);
}
}

\newcommand\subtitlebar{%
\tikz[baseline,trim left=1cm,trim right=3.05cm] {%
    \node[
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (b) at (3.05cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (b.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (b.east) |- (\textwidth+2cm,-0.75ex);
}%
}

\titleformat{\subsection}{\normalfont\large\sffamily}{}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\subsection}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\subsection,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesubsection}{\arabic{subsection}}


\titleformat{\section}{\LARGE\sffamily}{}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\section,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesection}{\arabic{section}}
\begin{document}
\chapter{This is a test}
\section{Section}
\lipsum[4-5]
\subsection{Subsection}
\lipsum[9]
\end{document}

在此处输入图片描述

如果您想删除规则但保留点,您可以为点定义一个命令:

\newcommand\titledot{%
\tikz[baseline=-0.65ex] {%
\path[fill=red!70!blue] (0,0) circle (.5ex);
  }
}

然后使用

\titleformat{\section}{\LARGE\sffamily}{\llap{\titledot}}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

一个例子:

\documentclass[12pt]{book}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usetikzlibrary{shapes.misc,arrows}
\newcommand\titlebar{%
\tikz[baseline,trim left=0.5cm,trim right=2.5cm] {%
    \node [
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (a) at (2.5cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (a.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (a.east) |- (\textwidth+3cm,-0.75ex);
}
}

\newcommand\subtitlebar{%
\tikz[baseline,trim left=1cm,trim right=3.05cm] {%
    \node[
        text = red!70!green,
        anchor= base east,
        minimum height=3.5ex] (b) at (3.05cm,0.6ex) {%
    };
   \path[fill=red!70!blue] (b.east) circle (.5ex);
   \draw[color=red!70!blue, thick,rounded corners=1ex] (b.east) |- (\textwidth+2cm,-0.75ex);
}%
}

\newcommand\titledot{%
\tikz[baseline=-0.65ex] {%
\path[fill=red!70!blue] (0,0) circle (.5ex);
  }
}

\titleformat{\subsection}{\normalfont\large\sffamily}{\llap{\titledot}}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\subsection}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\subsection,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesubsection}{\arabic{subsection}}


\titleformat{\section}{\LARGE\sffamily}{\llap{\titledot}}{0cm}{\textcolor{blue!60!green}{#1}}
\titlespacing*{\section}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{name=\section,numberless}{0cm}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand*{\thesection}{\arabic{section}}
\begin{document}
\chapter{This is a test}
\section{Section}
\lipsum[4-5]
\subsection{Subsection}
\lipsum[9]
\end{document}

在此处输入图片描述

顺便说一句,\sf这是一个 TeX 命令,在现代 LaTeX 文档中不应再使用;请改用\sffamily

相关内容