引用某个部分没有问题,但引用某个章节时,章节号后面会出现一些奇怪的空格。见附图:
这是我的代码
\documentclass[12pt,a4paper,twoside,fleqn,openright]{book}
% use quite a lot of packages
\usepackage{amsfonts,amssymb,amsmath,bm}
\usepackage{enumerate}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage[slovene]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{ifthen}
\usepackage[customcolors]{hf-tikz}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{ifoddpage}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage{titlesec}
\usepackage{pdfpages}
\usepackage{nameref}
\usepackage{multirow}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{enumitem}
\usepackage[numbib]{tocbibind}
\usepackage{url}
\usepackage{cite}
\usepackage{upgreek}
\usepackage[inner=30mm,
outer=25mm,
top=30mm,
bottom=25mm]{geometry}
% paragraph settings
\setlength\parindent{0pt}
\setlength{\parskip}{1.5ex plus 0.5ex minus 0.5ex}
% set equation environment indentation
\setlength{\mathindent}{0.5cm}%
% set itemize environment whitespacing and left margin
\setlist[itemize]{noitemsep,nolistsep, leftmargin=*}
% set table and figure captions
\captionsetup[table]{skip=10pt,singlelinecheck=false}
\captionsetup[figure]{justification=centering}
% set tablename to Preglednica
\AtBeginDocument{%
\renewcommand\tablename{Preglednica}
}
% command for multiline cell in table
\newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}}
\newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}}
% set section and tableofcontents depth
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\def\labelitemi{--}
% accordingly format a chapter definition
\titleformat{\chapter}[display]
{\bfseries}{}{0pt}{\Huge\thechapter}
% set fancy_nohead fancy header
\fancypagestyle{fancy_nohead}{
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\chead{}
\cfoot{}
}
% assign no_header
\assignpagestyle{\chapter}{fancy_nohead}
% section and chapter formatting
\renewcommand{\thechapter}{\arabic{chapter}.\quad}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thesubsubsection}{\thesubsection\arabic{subsubsection}.}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{chapter}.\arabic{equation}}
\renewcommand\labelenumi{(\theenumi)}
\DeclareMathOperator{\E}{\mathbb{E}}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\begin{document}
\chapter{Test}\label{cha:test}
Something written here.
\chapter{New test}\label{cha:new_test}
Reference to Chapter \ref{cha:test} \nameref{cha:test}.
\end{document}
有一行肯定有问题,因为简单地写
\documentclass[12pt,a4paper,twoside,fleqn,openright]{book}
\usepackage[slovene]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\begin{document}
\chapter{Test}\label{cha:test}
Something written here.
\chapter{New test}\label{cha:new_test}
Reference to Chapter \ref{cha:test} \nameref{cha:test}.
\end{document}
不再有问题。
有人知道哪个包有问题或者知道解决方法吗?
答案1
改变计数器的表示方式chapter
是这里的问题。也就是说,
\renewcommand{\thechapter}{\arabic{chapter}.\quad}
\quad
导致在引用中添加额外的空格 (a )。很可能您已重新定义\thechapter
,因为您希望在实际章节标题中章节编号和标题之间有一些额外的空格。这可以通过使用titlesec
的\titleformat
:
\titleformat{\chapter}[display]
{\bfseries}{}{0pt}{\Huge\thechapter.\quad}
此外,由于您的其他节号重新定义以 结尾.
,因此对这些节号的引用也将包含句号.
,这并不理想。相反,重新定义层级地和没有末尾的句点。而是将末尾的句点作为分段显示的一部分添加。一种方法是重新定义\@seccntformat
(参见如何在章节编号后添加点?):
\makeatletter
\renewcommand{\@seccntformat}[1]{#1.}
\makeatother
我所说的分层是指\the...
在下属计数器表示中使用任何父计数器:
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
上面的命令集有点多余,因为book
无论如何这都是该类的默认设置。