2017-05-06 63 views
0

我使用下面的代码,它使用\ 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} 

虽然输出是不错,我以前无法进入的空行“代码”,‘输出’和文字部分构成:

enter image description here

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

There's no line here to end. 

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

回答

0

如记录here,您可以使用下面的命令之一取决于你想要多大的空间跳过:

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

现在就来试试你所尝试的。
是否有可能使用\\\newline\linebreak这里?

是的,但你需要东西在这些命令之前,因为错误消息说,没有行结束。
您可以使用非打破空间,~,这些命令之前。

因此,所有的以下的也将工作:

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

另一个相关岗位:Lengths and when to use them