新手尝试修复边距

新手尝试修复边距

我有一个使用模板创建的文档,没有任何问题,但有一个部分对我来说仍然很神秘。我想设置边距,使两边的水平边缘距离相等。

我看到模板中有两个命令用于指定水平设置,我更改了其中的数字以获得我喜欢的边距。但是,每次我更改这些值时,值都会向右或向左移动。我希望整个文本在 A4 纸上居中。

\addtolength{\hoffset}{-2.75cm}
\addtolength{\textwidth}{5.5cm}

我已经尝试过,上面这两行设置了边距。如何添加新命令或更改定义,以便我可以设置文本始终居中?

在LaTeX文档中,有一个名为“style”的文件夹,其中有两个文件:head.texheader.tex,其中主文件夹中有main.tex

main.tex:

\documentclass[a4paper]{article}
\usepackage{nicematrix}
\input{style/head.tex}
\usepackage{caption}
\newcommand{\assignmentnumber}{1} % replace X with the lab session number
\newcommand{\coursename}{coursename}
\usepackage{mathtools}
\usepackage{nicematrix}
\usepackage{blkarray, bigstrut} 
\usepackage{braket}
\usepackage{subfig}
\usepackage{float}
\begin{document}
\input{style/header.tex}
\section{section 1}
\subsection{subsection 2}
\begin{equation}
    a= b+c
\end{equation}
\end{document}

style/head.tex

\addtolength{\hoffset}{-2.75cm}
\addtolength{\textwidth}{5.5cm}

\addtolength{\textheight}{5cm}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0in}
\addtolength{\voffset}{-3.50cm}

\usepackage[square,sort,comma,numbers]{natbib}
\usepackage{blindtext} % Package to generate dummy text
\usepackage{charter} % Use the Charter font
\usepackage[utf8]{inputenc} % Use UTF-8 encoding
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage{amsthm, amsmath, amssymb} % Mathematical typesetting
\usepackage{float} % Improved interface for floating objects
\usepackage{hyperref} % For hyperlinks in the PDF

\usepackage{bookmark}
\makeatletter
\renewcommand\@seccntformat[1]{}
\makeatother

\usepackage{graphicx, multicol} % Enhanced support for graphics
\usepackage{xcolor} % Driver-independent color extensions
\usepackage{pseudocode} % Environment for specifying algorithms in a natural way
\usepackage[mmddyy]{datetime} % Uses YEAR-MONTH-DAY format for dates

\usepackage{fancyhdr} % Headers and footers
\pagestyle{fancy} % All pages have headers and footers
\fancyhead{}\renewcommand{\headrulewidth}{0pt} % Blank out the default header
\fancyfoot[L]{} % Custom footer text
\fancyfoot[C]{} % Custom footer text
\fancyfoot[R]{\thepage} % Custom footer text
\newcommand{\note}[1]{\marginpar{\scriptsize \textcolor{red}{#1}}} % Enables comments in red on margin

\DeclareMathOperator*{\argmin}{arg\,min}

\usepackage[T1]{fontenc}

\usepackage[framed]{matlab-prettifier}

style/header.tex

\fancyhead[C]{}
%\hrule \medskip
\begin{minipage}{0.295\textwidth} 
\raggedright
%\footnotesize
\large
name\hfill
%\youremail
\end{minipage}
\begin{minipage}{0.4\textwidth} 
\centering 
\large 
\textbf{central title \assignmentnumber}
\normalsize 
\end{minipage}
\begin{minipage}{0.295\textwidth} 
\raggedleft
\coursename
%\today\hfill\\
\end{minipage}
\vspace{-0.5em}
{\hrule height 0.0200cm}
%\medskip\hrule
\hrule
%\bigskip

相关内容