I am new to RMarkdown and I have the following I am knitting into PDF
$$
log( \text{employed}) = \beta_0 \beta_1*log( adult \ wage ) \\
\beta_2*jobs \ created \beta_3*jobs \ destroyed \beta_4*mw \\
\beta_5*teen \ pop \beta_6*teen \ wage* \mu_i \delta_{it} \alpha_{it} \kappa_{ir}
$$
While the display that appears under this chunk projects the line breaks correctly, the output file has the equation run off the margins
CodePudding user response:
Maybe this solution?
header-includes:
- \usepackage{amsmath}
\begin{equation}
\begin{split}
log( \text{employed}) = \beta_0 \beta_1*log( adult \ wage ) \\
\beta_2*jobs \ created \beta_3*jobs \ destroyed \beta_4*mw \\
\beta_5*teen \ pop \beta_6*teen \ wage* \mu_i \delta_{it} \alpha_{it} \kappa_{ir}
\end{split}
\end{equation}
or this:
\begin{gather}
log( \text{employed}) = \beta_0 \beta_1*log( adult \ wage ) \nonumber \\
\beta_2*jobs \ created \beta_3*jobs \ destroyed \beta_4*mw \\
\beta_5*teen \ pop \beta_6*teen \ wage* \mu_i \delta_{it} \alpha_{it} \kappa_{ir} \nonumber
\end{gather}
Second looks cooler ;)
CodePudding user response:
I would use an align*
environment in this case, that allows alligned or multiline equations. The *
suppresses the equation numbers. In addition I made a backslash in front of the \log
, added \_
and used \cdot
instead of a multiplication *
and finally placed the
at the begining under the =
.
\begin{align*}
\log(\text{employed}) & = \beta_0 \beta_1 \cdot \log( adult\_wage )\\
& \beta_2 \cdot jobs\_created \beta_3 \cdot jobs\_destroyed \beta_4 \cdot mw\\
& \beta_5 \cdot teen\_pop \beta_6 \cdot teen\_wage \cdot \mu_i \delta_{it} \alpha_{it} \kappa_{ir}
\end{align*}
You may also consider to typeset multiletter variables upright as text or to remove redundant \cdot
multiplication operators if you want.
CodePudding user response:
I think this is more of a LaTeX question than an RMarkdown one.
I'm actually surprised it's rendering your display like you want at all -- LaTeX doesn't usually like having line breaks inside the displaymath environments. I'm also surprised that your document is successfully knitting for that same reason, but I guess you're knitting to HTML which is apparently a bit more forgiving than knitting to PDF.
At any rate, here is a possible fix:
\begin{align*}
log( \text{employed}) & = \beta_0 \beta_1*log( adult \ wage ) \\
& \qquad \beta_2*jobs \ created \beta_3*jobs \ destroyed \beta_4*mw \\
& \qquad \beta_5*teen \ pop \beta_6*teen \ wage* \mu_i \delta_{it} \alpha_{it} \kappa_{ir}
\end{align*}
Changes:
- Replace the $$ displaymath environment with
align*
, which will give you better control over the left/right alignment. (The*
character instructs TeX not to number this equation for you.) - Use the
&
character to control how things should be aligned from left to right. The\qquad
will add a bit of padding to offset the continuing lines to the right, which is the typical thing to do for expressions that extend over multiple lines.
Now, some further suggestions that I didn't implement above:
- Consider replacing your original
log
with\log
for nice typsetting of that function. - Consider adding a
\text{...}
wrapper around all your variable names (e.g.adult wage
,jobs created
, etc.) to make them look nice as well. You'll want to remove the\
spacing if you do this. Parentheses around these names may help readability when the name includes a space, or you could join the names with an underscore character (\_
in text mode). - (This one is extremely nitpicky:) Notice that the spacing on the
\:
, i.e.
... *\log(\text{adult\_wage}) \: \\
EDIT: After reflecting on tpetzold's answer, I realized I should change the alignment keys: the second and third lines should start to the right of the equals sign, and should be offset to the right a bit for visual distinction.