粗体文本未与下一行对齐

粗体文本未与下一行对齐

“练习 1-2”、“1-3”和“1-4”的格式符合我的要求,但“1-5”与文本的其余部分相比不自然地向右移动。最后一部分我遗漏了什么?

这是我的代码:

Create an int variable that contains your age. Name the variable “myAge”.\newline\newline
\textbf{Exercise 1-3}\newline
Suppose you were to create two string variables that are equal to “11.5” and “3.8.” If you were to add them together into a new string variable, what would that equal?\newline\newline
\textbf{Exercise 1-4}\newline
What is the largest number an int can store? Hint: Look on\newline \newline
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types\newline
to answer this. Being able to read programming language documentation is important in the programming field.\newline\newline

\textbf{Exercise 1-5}\newline
Find the bug in this code: \newline
\begin{lstlisting}
/*
Creates integer variables and sets them to different values.

int x = 7;
int y = 3;
int z = 2;
\end{lstlisting}

答案1

发布的代码会产生多个以下形式的警告

Underfull \hbox (badness 10000) in paragraph at lines 5--12

警告您放置不当\newline。您永远不应该将这些放在连续或段落末尾。但是,\newline在粗体标题后单独放置而不给出警告也是错误的,因为它们不构成标题,因此例如不会阻止在标题后立即分页。

1.5 示例是唯一一个以段落开头(由于有空白行)的示例,因此通过段落缩进进行缩进。

最好让使用\newtheorem自动编号构造声明的节或练习环境,但从发布的代码开始,进行简单的全局编辑以删除\newline并使用未编号的节标题\section*会产生

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{listings,xurl}
\begin{document}

Create an int variable that contains your age. Name the variable “myAge”.




\section*{Exercise 1-3}


Suppose you were to create two string variables that are equal to “11.5” and “3.8.” If you were to add them together into a new string variable, what would that equal?




\section*{Exercise 1-4}


What is the largest number an int can store? Hint: Look on
\url{https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types}
to answer this. Being able to read programming language documentation is important in the programming field.





\section*{Exercise 1-5}


Find the bug in this code: 


\begin{lstlisting}
/*
Creates integer variables
and sets them to different values.
*/
int x = 7;
int y = 3;
int z = 2;
\end{lstlisting}
\end{document}

相关内容