删除 ``center`` 之前的空格

删除 ``center`` 之前的空格
\documentclass[12pt] {article}
\usepackage{palatino}
\usepackage{fancyvrb}
\usepackage{authblk}
\usepackage{fancyhdr}
\usepackage{titlesec}
\def\baselinestretch{2.0}
\titleformat{\paragraph}{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\setlength{\textwidth}{18cm} 
\setlength{\textheight}{21cm}
\setlength{\evensidemargin}{-0.15cm}
\newcommand{\toright}[1]{%
    \leavevmode\unskip\nobreak\hfill\penalty13 
    \null\nobreak\hskip1em plus1fill\hbox{#1}%
}
\setlength{\oddsidemargin}{-0.15cm}
\title{\textbf{XXXXXX}}
\author{XXXXXXX}
\affil{\textbf{XXX}\;XXXX}
\affil{\textbf{XXX}\;XXXX}
\date{}

\begin{document}
    \maketitle\vspace{-1cm}
    \newpage
    \tableofcontents
    \pagestyle{fancy} \fancyhf{} 
    \fancyhead[LO]{XXXX}
    \fancyhead[RE]{XXXX}
    \fancyfoot[CE,CO]{\thepage} 
    \renewcommand{\headrulewidth}{1pt}
    \renewcommand{\footrulewidth}{1pt}
    
    \newpage
    \begin{enumerate}
        \section{ABC}
    \item value to the \verb|main| function. Instead it displays the result on the console. So we write {\fontfamily{qcr}\selectfont void sum (int a, int b)}. \\
    The \verb|main| function accepts the inputs and find \verb|sum| function in it. Suddenly it calls the \verb|sum| function and sends the inputs to \verb|sum| function. The \verb|sum| function takes the inputs and calculates the result and displays it on the console. Then the function control automatically returns to the \verb|main| function and finds the closing brace "$\}$" and terminates the program.
    \item \textbf{function with no argument and return type:}\\
    Here the \verb|sum| function has no argument and therefore we write \verb|sum()| (or we can write {\fontfamily{qcr}\selectfont sum (void)}). Since the function has return type (suppose \verb|int|), so we write \verb|int sum()| or {\fontfamily{qcr}\selectfont int sum(void)}.\\
    Here the \verb|main| function at first finds the \verb|sum| function and calls it. The \verb|sum| function then accepts the inputs and calculates. Since the \verb|sum| function has return type, so it returns the result to the \verb|main| function. \verb|main| function then receives the results and prints it on the console.
    \begin{center}
        \begin{BVerbatim}
    /* Adding two numbers using function*/
#include<stdio.h>
int sum ();                
            
void main ()
{
   int c;                 
   c= sum();   
   printf("\n The sum is = %d",c);
}
            
int sum ()     
{
   int x,y,z;
   printf("Enter the two numbers: ");
   scanf("%d, %d", &x, &y);
   z= x+y;
   return z;
}
        \end{BVerbatim}
    \end{center}
    \item \textbf{function with no argument and no return type:}\\
    Here the \verb|sum| function has no argument and therefore we write \verb|sum()| (or we can write {\fontfamily{qcr}\selectfont sum (void)}). Since the function has no return type, so we write \verb|void sum()| or {\fontfamily{qcr}\selectfont void sum(void)}.\\
    Here the \verb|main| function at first finds the \verb|sum| function and calls it. The \verb|sum| function then accepts the inputs and calculates. Since the \verb|sum| function has no return type, so it cannot return the result to the \verb|main| function. So the \verb|sum| function itself prints the result on the console. Then the function control automatically returns to the \verb|main| function and finds the closing brace "$\}$" and terminates the program.
    \begin{center}
        \begin{BVerbatim}
    /* Adding two numbers using function*/
#include<stdio.h>
void sum ();                
            
void main ()
{
   sum();                
}
            
void sum ()     
{
   int x,y,z;
   printf("Enter the two numbers: ");
   scanf("%d, %d", &x, &y);
   z= x+y;
   printf("\n The sum is = %d",z);
}
        \end{BVerbatim}
    \end{center}
    \end{enumerate}
\end{document}

据我所知,我无法分成center多页。但我需要这些编码位于页面中间(居中对齐)。因此,如果我删除center并使用verbatim,则空白处会被删除,但编码会与页面左对齐。
那么我需要什么

  1. 编码中心对齐
  2. 字体是qcr
  3. 将页面
    全部拆分在一起。

我可以使用{\fontfamily \selectfont {text}},但我认为这个过程对于大型编码来说相当费力。

编辑:我不想减少\def\baselinestretch{2.0}到 1 或者小于 2 的数字。

相关内容