我无法编译以下文件。我收到多个无法解释的错误。有人能帮助我吗?
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\title{Project 1}
\author{[email protected]}
\section{Tools}
Text
\section{Algorithm}
Text. \newline
Text:
\[ min_{\textbf{w}} \sum_{i=1}^n (y_i - \textbf{w}^T \textbf{x_i})^2 + \lambda \|\textbf{w}\|_2^2 \]
\newline
Text:
Text
\section{Features}
\section{Parameters}
\end{document}
答案1
您希望将表示向量的变量设为粗体,而不是其下标。要在数学模式下将字母设为粗体,最好的方法是使用\mathbf
;但是,最好将其隐藏在个人命令中:
\newcommand{\vect}[1]{\mathbf{#1}}
这样你的文档就变成了
\documentclass{article}
\usepackage{amsmath} % necessary for math intensive documents
\newcommand{\vect}[1]{\mathbf{#1}}
\begin{document}
\title{Project 1}
\author{[email protected]}
\maketitle
\section{Tools}
Text.
\section{Algorithm}
Text. Text:
\[
\min_{\vect{w}} \sum_{i=1}^n (y_i - \vect{w}^T \vect{x}_i)^2 +
\lambda \lVert\vect{w}\rVert_2^2
\]
Text.
\end{document}
为什么要间接地这样做?有几个原因。让我们看看两个主要原因:
您正在标记您的文档;当您想要在打字稿中查找向量时,您会寻找
\vect
可能\mathbf
用于其他目的的向量。如果你认为粗体斜体毕竟更好(例如,ISO规则规定矢量采用粗体斜体),你可以简单地更改一在您的文档中行(并将调用添加到包中):
\usepackage{bm} \newcommand{\vect}[1]{\bm{#1}}
关于打字风格的注释。
不要使用
\newline
;段落应该在打字稿中用空行简单分隔。打字稿中显示的公式前切勿留空行。
最常见的运算符已经有定义:用于
\min
“最小”运算符。请注意,它是
\vect{x}_i
而不是\vect{x_i}
,因为下标附加在变量名之后,并且不应该特殊格式化。使用
amsmath
(建议用于包含数学的文档),而不是\|
表示双线,最好使用特定分隔符\lVert
和\rVert
。查看文档mathtools
以了解标记文档的更好方法(\norm
命令说明)。
答案2
不允许\mathbf
在公式中使用。\textbf
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\title{Project 1}
\author{[email protected]}
\section{Tools}
Text
\section{Algorithm}
Text.
Text: %if you don't want the next line to be indented, use \noindent at the beginning of the line.
\[ \min_{\mathbf{w}}\sum_{i=1}^n (y_i - \mathbf{w}^T \mathbf{x}_i)^2 + \lambda \|\mathbf{w}\|_2^2 \]
Text:
Text
\section{Features}
\section{Parameters}
\end{document}
答案3
\documentclass[preview,border=12pt,12pt]{standalone}% change this line with your own document class below
%\documentclass{article}
%\usepackage{graphicx} <=== do you really need this graphicx package when you don't import any images?
% I move this setting to the preamble
\title{The Joy of \TeX}
\author{[email protected]}
\date{\today}
% you don't need the following two lines in your production
\newlength\buffer
\buffer=\parindent\relax
\usepackage{lipsum}% disable this package in your production. I use here just to produce dummy text.
\usepackage{amsmath}% use this package if you want to get more andvanced mathematics macros.
\begin{document}
\parindent=\buffer\relax% you don't need this line in your production
\maketitle
\section{Tools}
\lipsum[1]
\section{Algorithm}
\lipsum[2]
The following equation is fun, (by the way, you don't need to give a newline before a displayed equation)
\[
\min_{\mathbf{w}}
\sum_{i=1}^n \left(y_i - \mathbf{w}^T \mathbf{x}_i\right)^2
+ \lambda \lvert\mathbf{w}\rvert_2^2
\]
Isn't it? You don't need to add a newline after the displayed equation.
\lipsum[3]
\section{Features}
\section{Parameters}
\end{document}