如何在 Latex 的新命令中添加空行

rns*_*nso 3 macros latex

我正在使用以下使用 \newcommand (宏)的代码:

\documentclass[12pt]{article}

\usepackage{color}
\usepackage{graphicx}

\begin{document}

% definition of new commands: 
\newcommand{\mytitle}[1]{\LARGE\color{black}\centering\textbf{#1\newline}}   
        % NEWLINE WORKS IN ABOVE LINE
\newcommand{\mycode}{\small\color{green}Code:\scriptsize\leftskip30pt\color{red}\\*}%   
        % CANNOT ADD NEWLINE BEFORE "Code:" IN ABOVE LINE
\newcommand{\mytext}{\normalsize\color{black}\leftskip0pt}
\newcommand{\myoutput}{\small\color{green}Output:\scriptsize\leftskip30pt\color{blue}\\}%   
        % CANNOT ADD NEWLINE BEFORE "Output:" IN ABOVE LINE

\quote   % to prevent indentation of first line; 

% main text starts here: 

\mytitle{Simple text, code and figure.}

\mytext
This is normal text- part 1.\\ 
This is normal text- part 1.\\ 
This is normal text- part 1.\\ 

\mycode
This is code line 1.\\ 
This is code line 2.\\ 
This is code line 3.\\ 

\myoutput
This is output line 1.\\ 
This is output line 2.\\ 
This is output line 3.\\ 

\mytext
This is normal text- part 2.\\ 
This is normal text- part 2.\\ 
This is normal text- part 2.\\ 

\mycode
This is code part 2.\\ 
This is code part 2.\\ 
This is code part 2.\\ 

\myoutput
This is output part 2.\\ 
This is output part 2.\\ 
This is output part 2.\\ 

\mytext
The last line in normal text.\\ 

\end{document}
Run Code Online (Sandbox Code Playgroud)

虽然输出没问题,但我无法在“代码:”、“输出”和文本部分之前输入空行:

在此处输入图片说明

我尝试使用\\ \newline\linebreak[1]在箭头标记的点处添加空行,但它们都会产生以下错误:

There's no line here to end.
Run Code Online (Sandbox Code Playgroud)

如何在文本的代码、输出和文本部分之前添加空行?谢谢你的帮助。

Sar*_*ama 8

如此处所述,您可以根据要跳过的空间大小使用以下命令之一:

  • \smallskip
  • \medskip
  • \bigskip
  • 或更灵活的一个: \vspace{length-of-space}

现在来看看你已经尝试过的。
是否有可能使用\\\newline\linebreak在这里?

是的,但是在这些命令之前你需要一些东西,因为正如错误消息所说,没有行结束。
您可以~在这些命令之前使用不间断空格 , 。

因此,以下所有内容也将起作用:

  • ~\\
  • ~\newline
  • ~\linebreak

另一个相关帖子:长度和何时使用它们