不使用 \newline 命令插入新行

不使用 \newline 命令插入新行

我正在寻找插入新行,只需按下键盘上的“Enter”按钮即可。

有解决办法吗?

这是“无聊”的方式:

\section{mySection}
    My really really really long text.\newline
    A new text line.

这是一种更短、更不无聊的方法:

\section{mySection}
    My really really really long text.

    A new text line.

我采用了最后一个解决方案,但是如果文本真的很长,它会在乳胶编辑器上创建很多空白,这对我来说不是很好。

有没有办法仅使用以下代码来创建新行?

\section{mySection}
    My really really really long text.
    A new text line.

答案1

尽管很难说清楚你到底想做什么,但除了形成小块的文本之外,让行尾(EOL)等同于\\或是一个坏主意\newline

我现在知道一开始这很无聊,但我的建议是学习 \newline 和 \\ 之间有什么区别?\linebreak以及\par(另请参阅使用 \par 代替两个新行的缺点),然后只使用空行来创建新段落(而不是创建新行),并尽可能少地使用换行命令(在表格行末尾......仅此而已。)因为可能有更好的方法来获得你想要的东西而没有任何\\。(我在考虑列表,带有文本的框等)

说,除了obeylines环境,另一个选择是parse linesverbatim环境。哪个更好取决于你想要什么,因为树环境有几个显著的差异,你可以在这个例子中进行比较:

平均能量损失

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\pagestyle{plain}
\usepackage{xcolor} % Some colors to distinguish environments in the compiled example
\usepackage{parselines} 

% huge indentation of paragraph only for demonstration purposes. 
\setlength{\parindent}{5em} 
% some paragraph skip to better distinguish  lines of different paragraphs  
\setlength{\parskip}{.8em} 


\begin{document}

This is the \texttt{document} environment.
The \LaTeX{} commands are recognized here without problems. 
EOL (Linefeed and carriage return) are just ignored. But long lines are well formatted. Test: This is a long sentence to test the text wrap in a pragraph. 
\\ This is a new line with \verb|\\|.
\newline This is another \verb|\newline| .
\par This is a new paragraph.



This is another paragraph. Blank lines (no matter how many) means a new paragraph, \textbf{not a new line}. Note  that a new paragraph can add indentation in the first line and vertical space, as in this example (or not, depending of \verb|\parindent| and \verb|\parskip| values. 

\color{blue!50!black}
\begin{obeylines}
This is the \texttt{obeylines} environment
Some  \LaTeX{} commands can be included  
This is a new line, but treated as a paragraph. 
This is another line (and another paragraph).


Blank lines are just ignored.

Long lines are well formatted (as paragraphs). Test: This is a long sentence to test the text wrap in a pragraph. This is a long sentence to test the text wrap in a pragraph. 

\end{obeylines}

\color{red!30!black}
\begin{parse lines}[\noindent]{#1\\}
This is the \texttt{parse lines} environment (need the \texttt{parselines} package)
Some \LaTeX{} commands can be included also (but not all).  
This is a line.   
This is another line.



And blank lines are just blank lines.

Long lines are well formatted (as lines): Test: This is a long sentence to test the text wrap in a pragraph. This is a long sentence to test the text wrap in a pragraph. 
\end{parse lines}

\color{green!30!black}
\begin{verbatim}
This is the verbatim environment.
The \LaTeX{} command are NOT recognized here. 
And use teletype text (as using \textt{})
But linefeed and carriage return are recognized.
So this is a new line


And blank lines are just blank lines.

And long lines are just long lines: Test: This is a long sentence to test the text wrap in a pragraph. This is a long sentence to test the text wrap in a pragraph. 

\end{verbatim}

\end{document}

答案2

您可以使用\obeylines

\documentclass{article}
\begin{document}
\bgroup\obeylines
Here line breaks
are respected.
\egroup
Here they
are not.
\end{document}

休息

答案3

您可以轻松尝试以下方法:

\\

它的结果与

\newline

答案4

一种有效的方法是使用

Sentence \\
~\\
Sentence

这里的关键命令是~\\

相关内容