我正在使用以下使用\ newcommand(macro)的代码:
\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}
虽然输出没问题,但我无法在“代码:”,“输出”和文字部分之前输入空白行:
我尝试使用\\
\newline
和\linebreak[1]
在箭头标记的点处添加空行,但它们都会产生以下错误:
There's no line here to end.
如何在代码,输出和文本文本部分之前添加空白行?谢谢你的帮助。
答案 0 :(得分:2)
根据记录here,您可以根据要跳过的空间使用以下命令之一:
\smallskip
\medskip
\bigskip
\vspace{length-of-space}
现在来看你尝试过的东西。
可以在这里使用\\
,\newline
和\linebreak
吗?
是的,但是在这些命令之前你需要某些东西,因为正如错误信息所说,没有一条线要结束。
您可以在这些命令之前使用不间断的空格~
。
所以以下所有方法也有效:
~\\
~\newline
~\linebreak
另一篇相关文章:Lengths and when to use them