我无论如何都无法让我的章节标题正确居中。我希望文档的总体布局有一个相当大的左边距(3.0 英寸)。当我想将某个东西(比如图片)移到该边距中时,我会使用调整宽度。这对于图形等东西很有效。我试图对章节标题采取类似的方法,但不起作用。它一直将其置于边距为 3.0 英寸的文本上方,而不是像我希望的那样将其置于页面中央。或者它会将其放置在页面的 1/3 左右。我做错了什么?
梅威瑟:
\documentclass{article}
\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}
\usepackage{changepage}
\let\oldsection\section
\renewcommand{\section}[2][]{
\begin{adjustwidth}{-2.0in}{0.0in}
\begin{minipage}[t]{\textwidth}
\oldsection{#2}
\end{minipage}
\end{adjustwidth}
}
%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]
\begin{document}
\section{Introduction}
\subsection{Sub Section 1}
\subsubsection{Sub Sub Section 1}
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
\end{document}
未对部分进行重新定义的 MWE:
\documentclass{article}
\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}
\usepackage{changepage}
%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]
\begin{document}
\section{Introduction}
\subsection{Sub Section 1}
\subsubsection{Sub Sub Section 1}
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
\end{document}
答案1
您实际上不必使用adjustwidth
:titlesec
有工具来实现这一点:\titlespacing
它接受 3 个参数,第一个参数用于更改标题的左边距。操作如下:
\documentclass{article}
\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in, showframe]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}
%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]
\titlespacing*{\section}{-2in}{4.5ex}{2.5ex}
\begin{document}
\section{Introduction}
\subsection{Sub Section 1}
\subsubsection{Sub Sub Section 1}
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
\section{A First Section}
Some text. Some more text. Some more text.
\end{document}