章节标题文本的悬挂缩进

章节标题文本的悬挂缩进

目前,Section 标题文本缩进已挂起,这要归功于 @Simon Dispa 的解决方案连字符包和标题文本字体设置导致错位。我还想让我的章节标题文本缩进像章节一样悬挂。以下是 MWE:

\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\usepackage[ 
left=2.5cm,
right=2.5cm, 
top=3cm, 
bottom=3cm,
headheight = 3\baselineskip,
headsep = 5mm,
a4paper
]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}


\newcommand*\myheaderfooterfont{\normalfont\bfseries\selectfont}
\newlength{\leftspace}% 
\setlength{\leftspace}{18ex}%
\newlength{\xindent}
\settowidth{\xindent}{\myheaderfooterfont\thechapter.\thesection\:}
\usepackage{varwidth}% 


\fancypagestyle{fancy}{%
    \fancyhf{}
    \fancyhead[OL]{\leftmark}
    \fancyhead[ER]{\begin{varwidth}{\dimexpr\textwidth-\leftspace}\myheaderfooterfont\raggedright\parindent-\xindent\rightmark\end{varwidth}}
    \fancyfoot{}
    \fancyfoot[RE,RO]{\thepage}
    \renewcommand\headrule
    {{     \color{blue}\rule{1\headwidth}{2.5pt}%       
    }}
}

\fancypagestyle{plain}{%
    \fancyhf{}%
    \renewcommand\headrule
    {{     \color{blue}\rule{1\headwidth}{0pt}%         
    }}      
}

\pagestyle{fancy}   

\usepackage{showframe}

\usepackage[none]{hyphenat}
\raggedright

\begin{document} 
    %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<added
    \frontmatter
    \chapter*{ABC}
    \markboth{ABC}{ABC}
    eeeheeyeyeyeyeyeeyeye
    \section*{DEG}
    dddheheheheheheheehehehe
    \pagebreak
    \section*{KJ}
    ddhheheheheheehehehheheheheheh
    \pagebreak
    \section*{KDH}
    dhddhhehehehehehehehehehehe

    \mainmatter
    %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<added
    \chapter{ABCD ffhfgrhr ejejejeje fhfhfhf ehehehehe dhddhdhellgl rkttkgkhihi eeeejejwnwn hhlhlnnmgjgj rjrrjoaoaoao rjjrjrrrj wwjwwwjwjw}
    
    eehehdhdhdhdddddd ddddddddddddddddddddd
    
    \pagebreak
    
    \section{Special keyboard characters gghthr rhrrhd fheheh fhehuw fhewiwi feiwiwd fiiwiwid fiiwiwi firiifn rokfkkvfvv fjjjeje jejeje djej}   
    
    
    \LaTeX{} has many symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and  \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
    The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file. 
    
    \clearpage
    
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf      
Some text.
\end{document}

答案1

更新更改标题字体。

尝试一下这个代码。 氨基酸

bb

Z Z

最后更新:匹配的空间和更高headheight

抄送

% !TeX TS-program = pdflatex    
\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\usepackage[ 
left=2.5cm,
right=2.5cm, 
top=3cm, 
bottom=3cm,
headheight = 3.5\baselineskip,%<<<<<<<<<<<<<<<<<<
headsep = 5mm,
a4paper
]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline} 

\usepackage{helvet}%<<<<<<<<<<<<<<<<<<<<

%****************************************
\usepackage{tabularx}% added <<<<<      
\newcommand*\myheaderfooterfont{\sffamily\bfseries\selectfont}  

\newlength{\leftspace}% for sections <<<<<<<<<
\setlength{\leftspace}{20ex}%set

\newlength{\Lheader}
\renewcommand{\chaptermark}[1]{\markboth{\uppercase{#1}}{}}% added <<<<<<<<<<<
\renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}}% added <<<<<<<<<<<

\fancypagestyle{fancy}{%
    \fancyhf{}  
    \fancyhead[OL]{\myheaderfooterfont%
        \ifnum\value{chapter}>0%
        \begin{tabularx}{\textwidth}{@{}lX}\uppercase{Chapter~\thechapter}&\raggedright\leftmark\end{tabularx}% changed <<<<<<<<<<
            \else\raggedright\leftmark\relax\fi}
        \fancyhead[ER]{\myheaderfooterfont%
                \settowidth{\Lheader}{\thesection\hspace*{12pt}\rightmark}  
                \ifnum\value{chapter}>0%
                \ifdim\Lheader>\linewidth%          
                \begin{tabularx}{\dimexpr\textwidth-\leftspace}{@{}lX} \thesection &\raggedright\rightmark\end{tabularx}%
                \else\begin{tabular}{@{}ll@{}} \thesection &\raggedright\rightmark\end{tabular}%
                \fi\else\hfill\raggedright\rightmark\relax\fi
    }% changed <<<<<
                
    \fancyfoot[RE,RO]{\thepage}
    \renewcommand\headrule{\color{blue}\rule{1\headwidth}{2.5pt}}
}
%****************************************

\fancypagestyle{plain}{%
    \fancyhf{}%
    \renewcommand\headrule
    {{     \color{blue}\rule{1\headwidth}{0pt}%         
    }}      
}

\pagestyle{fancy}   

\usepackage{showframe}

\usepackage[none]{hyphenat}
\raggedright %  important with  none hyphenat + none !!!!!!!!!!!!!!!!!

\begin{document} 
    
    \frontmatter
    \chapter*{ABC}
    
    \markboth{ABC1}{ABC2}
    
    eeeheeyeyeyeyeyeeyeye
    \section*{DEG}
    dddheheheheheheheehehehe
    \pagebreak
    \section*{KJ}
    ddhheheheheheehehehheheheheheh
    \pagebreak
    \section*{KDH}
    dhddhhehehehehehehehehehehe
    
    \mainmatter

    \chapter{ABCD ffhfgrhr ejejejeje fhfhfhf ehehehehe dhddhdhellgl rkttkgkhihi eeeejejwnwn hhlhlnnmgjgj rjrrjoaoaoao  }        
    eehehdhdhdhdddddd ddddddddddddddddddddd     
        
    \newpage                
    \section{Special keyboard characters gghthr rhrrhd fheheh fhehuw fhewiwi feiwiwd fiiwiwid fiiwiwi}  

    \LaTeX{} hasmany symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and  \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
    The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file.       
    \newpage        
    \section{Special keyboard characters}       
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf     
    \newpage        
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
                   
    \chapter{One short line}        
    \LaTeX{} has many symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and  \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
    The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file. 
    
    \section{Special keyboard characters}   
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf     
    \newpage        
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf     
    \newpage        
    Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf     

\end{document}

相关内容