无论是否使用titlesec
包,如何才能将节号(即\thesection
)放在右边距?我真的不知道。我尝试过一些实验,但没有任何结果。
梅威瑟:
%!TEX program = xelatex
\documentclass[
draft=false, % final mode
paper=portrait,
twoside=false,
open=right,
parskip=full,
headings=big,
version=last, %
italian, % language (passed to babel and other packages)
% (ngerman, english, french, ...)
]{scrbook} % Classes: scrartcl, scrreprt, scrbook
% ----------------------
% DIMENSIONI PAGINA
% ----------------------
\setlength{\oddsidemargin}{0.3cm}
\setlength{\textwidth}{0.7\textwidth}
\setlength{\marginparwidth}{2\marginparwidth}
\usepackage{lmodern}
\usepackage{amsmath} % advanced math symbols pkg
\usepackage{amsthm, amsthm}
\usepackage[utf8]{inputenc} % utf8 encoding
\usepackage{graphicx} % pictures support
\usepackage{longtable} % table on multiple pages support
\usepackage[italian]{babel} % language support
\usepackage{enumitem} % custom enumeration support
\usepackage{rotating} % Rotating pictures support
\usepackage{floatrow} % Support for floated images
\usepackage{hyperref} % Support for href in toc
\usepackage{marvosym} % Currency symbols
\usepackage{fancyhdr} % Fancy headers
\usepackage{array}
\usepackage{footnote}
\usepackage{setspace}
\usepackage{afterpage} % Permette di mettere i numeri di pagina nel footer se si usa il package Fancyhdr
\usepackage{textcomp} % Package for copyright glyph
\usepackage[newfloat]{minted} % Package for highlight code
\usepackage{appendix} %Package for appendices
\usepackage{chngcntr} %Package for list of figures numeration
\usepackage{csquotes}
\usepackage{fontspec}
\usepackage[protrusion=true]{microtype}
\usepackage{mwe}
% ----------------------
% CUSTOMIZATION CAPITOLI
% ----------------------
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{blindtext}
%\input{preamble/style-chapter}
\renewcommand*{\sectionformat}{%
\llap{\thesection\enskip}%
}
\renewcommand*{\subsectionformat}{%
\llap{\thesubsection\enskip}%
}
%\renewcommand*{\raggedsection}{\raggedleft} % Allinea a destra i titoli
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\raggedleft\normalfont\Large\bfseries} % format
%{\makebox[0pt][l]{ % label
% \makebox[\dimexpr\textwidth+\marginparsep-1.3cm][r]{
% \thesection
% }}
%}
{\makebox[0pt][r]{#1 \hspace*{0.01cm}\thesection}}
{0pt} % sep
{\phantomsection} % before
% ----------------------
% FOOTNOTE AL MARGINE
% ----------------------
\usepackage{marginfix} % --> gestisce correttamente il posizionamento ai margini
\usepackage[%
bottom, % Footnotes appear always on bottom. This is necessary
stable, % Make footnotes stable in section titles
perpage, % Reset on each page
side, % Place footnotes in the margin
ragged, % Use RaggedRight
marginal,
norule, % suppress rule above footnotes
multiple, % rearrange multiple footnotes intelligent in the text.
]{footmisc}
\setlength{\footnotemargin}{0.1mm} % --> distanza numero di nota a pie di pagine e testo
\definecolor{footnotecolor}{RGB}{78, 78, 78}
\def\footnotelayout{\raggedright\color{footnotecolor}} % --> raggedright coincide con text-align:left
% ----------------------
% CAPTION CUSTOMIZATION
% ----------------------
\usepackage[
format=plain,
justification=raggedright,
singlelinecheck=false
]{caption}
\captionsetup{figurename=FIGURE, labelsep=colon}
\captionsetup[figure]{font={color=footnotecolor,it,footnotesize},labelfont={color=black,bf,it,scriptsize}}
\captionsetup[listing]{font={color=footnotecolor,it,footnotesize},labelfont={color=black,bf,it,scriptsize}}
\renewcommand*{\figureformat}{ % --> elimina un punto di troppo sulla numerazione delle figure
\figurename~\thefigure
% \autodot% DELETED
}
% ----------------------
% FLOATING
% ----------------------
\floatsetup{
margins=hangright,
capposition=beside,
capbesideposition={bottom,right},
floatwidth=\textwidth
}
\begin{document}
\setminted{linenos,autogobble, frame=lines, framesep=3mm, tabsize=2, fontsize=\footnotesize,baselinestretch=1} %IMPOSTAZIONI
\chapter{Chapter}
\blindtext\footnote{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan rutrum dictum. Nunc volutpat egestas
ante non efficitur. Sed pellentesque vulputate scelerisque.}
\blindtext
\section{Section}
\blindtext
\end{document}
答案1
您可以重新定义\sectionlinesformat
:
\renewcommand*\sectionformat{\textcolor{blue}{\thesection\autodot}}
\addtokomafont{section}{\rmfamily}
\makeatletter
\renewcommand*\sectionlinesformat[4]{%
\ifstr{#1}{section}
{\raggedleft#4\makebox[0pt][l]{\hskip\marginparsep#3}}
{\@hangfrom{\hskip#2#3}#4}% use original definition for subsection, subsubsection etc.
}
\makeatother
不含不相关的包和设置的示例:
\documentclass[
draft=false,
paper=portrait,
twoside=false,
open=right,
parskip=full,
headings=big,
version=last,
%italian,
]{scrbook} % Classes: scrartcl, scrreprt, scrbook
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage[protrusion=true]{microtype}
\usepackage{blindtext}% only for dummy text
\usepackage{showframe}% to show the page layout
\usepackage{hyperref} % load as last package
\renewcommand*\sectionformat{\textcolor{blue}{\thesection\autodot}}
\addtokomafont{section}{\rmfamily}
\makeatletter
\renewcommand*\sectionlinesformat[4]{%
\ifstr{#1}{section}
{\raggedleft#4\makebox[0pt][l]{\hskip\marginparsep#3}}
{\@hangfrom{\hskip#2#3}#4}% use original definition for subsection, subsubsection etc.
}
\makeatother
\begin{document}
\chapter{Chapter}
\Blindtext[2]
\section{Section}
\blindtext
\end{document}
结果: