带有长标题的章节标题

带有长标题的章节标题

我正在尝试使用 latex 撰写论文,并且修改了要使用的模板,但部分章节标题出现了问题。具体来说,由于章节标题是两端对齐的,而不是左对齐,导致单词之间的间距很奇怪。

我正在使用 titlesec 包并尝试过:

\titleformat{\section}{\raggedright\large\sffamily\bf}{\thesection}{1em}{}

我还尝试通过添加强制 titlesec 使一切变得正确

\usepackage[raggedright]{titlesec} 

到我的序言,但似乎没有任何效果,标题文本仍然间距奇怪。我想可能是我的设置中的其他内容占了上风?

\documentclass[11 pt]{report}
%-----------------------------------------
%                  Packages
%-----------------------------------------

\usepackage{titlesec}
\usepackage[a4paper, scale=1.0, textwidth=145mm, textheight=237mm, layoutvoffset=0pt, layouthoffset=0pt, ignoremp, includehead, marginparsep=0pt, bottom=4cm, top=2cm, left=4cm, right=2.5cm, verbose=true, bindingoffset=0pt]{geometry} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[english]{babel} 
\usepackage{setspace} 
\usepackage[toc, page, header]{appendix} 
\usepackage{fancyhdr} 
\usepackage[plain]{fancyref} 
\usepackage{textcomp} 
\usepackage{sectsty}
\usepackage{balance} 
\usepackage{lastpage}
\usepackage[format=plain,justification=centering,singlelinecheck=false,font=small,labelfont=bf,labelsep=space]{caption} 

%-----------------------------------------------------------------------
%   MAIN PAGE SETUP
%-----------------------------------------------------------------------

\renewcommand{\rmdefault}{ptm} % sets roman font to Times ('ptm')
\renewcommand{\sfdefault}{phv} % sets serif font to Helvetica 
\renewcommand{\ttdefault}{lmtt} % sets text type font to Latin Modern Typewriter ('ptm')
\widowpenalty=500 
\clubpenalty=500 
\pretolerance=10000 
\tolerance=2000 %
\emergencystretch=10pt 

\titleformat{\section}{\fillleft\large\sffamily\bf}{\thesection}{1em}{} %formats the section titles 

\begin{document}

\onehalfspace
\chapter[Introduction]{Introduction}
\chaptermark{Introduction}
\label{ch:introduction} % label for referring to chapter in other parts of the thesis
\section[Importance]{Importance}\label{C1:Intro}

稍后填写

 \section[Synthesis]{Synthesis of averylongcompoundnamethatis toobigtofitinthisbox}

 blahblahblah

\end{document}

长标题图片

答案1

您已在加载包sectsty。然后使用

\sectionfont{\raggedright\large\sffamily\bfseries}

或者不是加载包 secsty 也\titleformat可以正常工作。如果您想允许连字符,请使用:

\usepackage{ragged2e}
\sectionfont{\RaggedRight\large\sffamily\bfseries}

答案2

\pretolerance值太大,阻止了连字符和随之而来的换行,因此将行拉长到下一个可能的位置换行,即toobig... 在关闭它之后问题消失(通过评论它)

\documentclass[11pt]{report}

\usepackage[a4paper, scale=1.0, textwidth=145mm, textheight=237mm, layoutvoffset=0pt, layouthoffset=0pt, ignoremp, includehead, marginparsep=0pt, bottom=4cm, top=2cm, left=4cm, right=2.5cm, verbose=true, bindingoffset=0pt]{geometry}
\usepackage{titlesec}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[english]{babel} 
\usepackage{setspace} 
\usepackage[toc, page, header]{appendix} 
\usepackage{fancyhdr} 
\usepackage[super,sort&compress,comma]{natbib} 
\usepackage[plain]{fancyref} 
\usepackage[version=3]{mhchem}
\usepackage{times,mathptmx}
\usepackage{textcomp} 
\usepackage{sectsty}
\usepackage{balance} 
\usepackage{graphicx} 
\usepackage{lastpage}
\usepackage[format=plain,justification=centering,singlelinecheck=false,font=small,labelfont=bf,labelsep=space]{caption} 

\newcommand{\mk}[1]{%
%
}


%-----------------------------------------------------------------------
%   MAIN PAGE SETUP
%-----------------------------------------------------------------------

% This section is relevant to formatting within chapters
\linespread{1.8} %1.5 line spacing
\renewcommand{\rmdefault}{ptm} % sets roman font to Times ('ptm')
\renewcommand{\sfdefault}{phv} % sets serif font to Helvetica 
\renewcommand{\ttdefault}{lmtt} % sets text type font to Latin Modern Typewriter ('ptm')
\pagestyle{fancyplain} % retains control of headers and footers
\fancyhf{}
\fancyheadoffset{0.0in} % margin size at header
\renewcommand{\headrulewidth}{0.4pt} % thickness of rule in header line (0pt will make it disappear)
\lhead{\fancyplain{}{}}
\rhead{\fancyplain{\leftmark}{\leftmark}} %prints current chapter name in the right header
\fancyfoot[R]{\thepage}
\chead{\fancyplain{}{}}
\renewcommand{\footrulewidth}{0.4pt} % thickness of rule in footer line

\headsep=12pt % Sets distance between header rule and text
\parindent=12pt % Sets indentation for each paragraph
\parskip=0.1in % Sets vertical space before a new paragraph
\widowpenalty=500 % elliminates widows (single lines of a paragraph on the top of the next page), see line below
\clubpenalty=500 % these two lines eliminate widows and orphans from the document, but may affect typesetting quality elsewhere.

%\pretolerance=10000 % turns off hyphenation

\tolerance=2000 % turns off hyphenation
\emergencystretch=10pt % turns off hyphenation


%  The following changes the Chapter Title format 

\titleformat{\section}{\raggedright\large\sffamily\bf}{\thesection}{1em}{} %formats the section titles 

% for a bit more fancy chapter and section titles use the following 12 lines:
\renewcommand{\thechapter}{\arabic{chapter}} 
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright
}%
[\vspace{2ex}%
\titlerule]
\renewcommand{\captionfont}{\sffamily}{\small}
\renewcommand{\captionlabelfont}{\bf}

\begin{document}

\onehalfspace
\chapter[Introduction]{Introduction}
\chaptermark{Introduction}
\label{ch:introduction} % label for referring to chapter in other parts of the thesis
\section[Importance]{Importance}\label{C1:Intro}
 Filling in later

 \section[Synthesis]{Synthesis of averylongcompoundnamethatis toobigtofitinthisbox}

 blahblahblah



\end{document}

相关内容