I am trying to add an equation in a new line. The problem is that the equation is too long for the line, and I need to break it manually. Otherwise, it just overlaps to the right column, or to the right margins (and looks ugly...).
Is there a way LaTeX can brake the equation for me, so it seems nice?
I'm attaching my latex code:
\begin{align*}
f(n)-f(0) &= A(n)-B(n)-C(n)-D(n)\cdot d-\left(A(0)-B(0)-C(0)-D(0)\cdot d\right) \\
&= A(n)-0-X-D(n)\cdot d-\left(0-0-0-0\right) \\
&= A(n)-X-D(n)\cdot d
\end{align*}
The problematic line is the first line, which is too long.
The breqn package is designed to split long equations automatically. It works very well in the majority of situations, but it's not as mature as the amsmath package. Here's how you'd write your example equation:
\documentclass{article}
\usepackage{breqn}
\begin{document}
\begin{dmath}
f(n)-f(0) = A(n)-B(n)-C(n)-D(n)\cdot d-\left(A(0)-B(0)-C(0)-D(0)\cdot d\right)
= A(n)-0-X-D(n)\cdot d-\left(0-0-0-0\right)
= A(n)-X-D(n)\cdot d
\end{dmath}
\end{document}
Note there is no markup for alignment or newlines, but the output looks essentially the same as if you used align.
I usually prefer to handle this by using the amsmath package and using the split structure. There are a bunch of useful structures in there for splitting equations across lines, but that's usually the simplest to use.
Many TeX installations will already have the package, but you can also get it from the AMS website.
The standard approach I've used in the past is an eqnarray. See for example this page.
As far as I know, this is not possible. When working inside a display, you are responsible for line breaks. How to line break, and how to continue on the next line in case of brackets, is a tough question for humans (check, for instance, the relevant section in Grätzer, "Math into LaTeX"), let alone for a computer.
Example:
when you break the first line after \left(, you need a \right. at the end, and \left. at the beginning of the next line (otherwise you'll get an error). Moreover, you'd want the beginning of the next line to be further right than the bracket produced by \left(
Related
The equation below does not display in latex. Also, the introductory text does not display properly(all words together without space and in italics)
A common form of this potential is the 12-6 Lennard Jones (LJ) potential
expressed as equation 2.7
\begin{align}
U_{ij}= 4\epsilon_{ij}[(\frac{\sigma_{ij}}{r_{ij})^12-
(\frac{\sigma_{ij}}{r_{ij})^6]
\end{align}
Also, in the text below, all words are together without space and in italics.
Where \epsilon_{ij} and \sigma{ij} represent well depth and diameter of
the atom respectively. \epsilon_{ij} and \sigma_{ij} for unlike atoms
are determined using Lorentz-Berthelot combination rules [44] given in
equations 2.8 and 2.9
Your help is appreciated.
I attach here a picture of the output.
This is because you're not using inline math mode properly. In the image you posted
it shows that your text is preceded by (what looks like) \epsilon_{ij}. \epsilon requires a math font, and therefore you should use $\epsilon_{ij}$. The same goes for any inline math you want to typeset. This would be the suggested/proper coding:
A common form of this potential is the 12-6 Lennard Jones (LJ) potential
expressed as equation~\eqref{eq:lj-potential},
\begin{equation}
U_{ij} = 4 \epsilon_{ij} [ (\frac{\sigma_{ij}}{r_{ij})^{12}
- (\frac{\sigma_{ij}}{r_{ij})^6 ] \label{eq:lj-potential}
\end{equation}
where $\epsilon_{ij}$ and $\sigma{ij}$ represent well depth and diameter of
the atom respectively. $\epsilon_{ij}$ and $\sigma_{ij}$ for unlike atoms
are determined using Lorentz-Berthelot combination rules~\cite{lorentz-berthelot}
given in equations~\eqref{eq:epsilon} and~\eqref{eq:sigma}.
Note the following:
Use equation for a single-line numbered equation; align is for multi-line equations (that may require alignment).
No blank line (paragraph break) before equation.
Use \labels and \refs (or \eqref, since you're using amsmath) since equation numbers can change. Let TeX take care of storing and recalling these numbers.
Use \cite to reference something in a bibliography.
Use $...$ (or \(...\)) for inline math (already discussed above).
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
U_{ij}= 4\epsilon_{ij}[
(\frac{
\sigma_{ij}
}{
(r_{ij})^{12} -
\frac{
\sigma_{ij}
}{(r_{ij})^6
}
}]
\end{align}
\end{document}
three groups were not closed properly in the equation.
Read about amsmath package.
I suggest you try to write as clean as possible.
Output
In
this article the author discusses the use of \# to put correct spacings after full stops that are not at the end of a sentence e.g. Mr. i.e. etc.
The macro suggested
\newcommand\etc{etc\#ifnextchar.{}{.\#}}
is not quite perfect since in the case (\etc more text) it produces (etc.more text).
I have seen a lot of authors who have made their own versions of the \etc macro, mostly variations on etc.\.
What macros for \etc, \ie, \etal, \eg produce the nicest results in the most situations?
Is this something too personal in taste to be solved in general?
Earlier I used macros for "et al.", etc., but nowadays I would discourage people from defining that kind of macros.
One problem is what you already observed: it's surprisingly tricky to get the definitions right so that they handle all special cases correctly (including the interactions with other packages – e.g., those that re-define the "\cite" command and tweak spacing before references).
But more importantly, even if you have a bunch of macros that suit your needs and you know how to use them, your co-authors are likely to be confused with exactly how to use your macros correctly in various special cases.
Hence I'd recommend that you avoid macros for trivial things such as "et al." and simply spell out everything by using standard Latex markup. After all, most cases don't need any special handling ("e.g." is often followed by a comma; "et al." is often followed by "~\cite", etc.), and whenever special handling is needed, all Latex users should know how to use commands such as "\ " and "\#".
In CVPR's style package, it is defined as:
\usepackage{xspace}
% Add a period to the end of an abbreviation unless there's one
% already, then \xspace.
\makeatletter
\DeclareRobustCommand\onedot{\futurelet\#let#token\#onedot}
\def\#onedot{\ifx\#let#token.\else.\null\fi\xspace}
\def\eg{\emph{e.g}\onedot} \def\Eg{\emph{E.g}\onedot}
\def\ie{\emph{i.e}\onedot} \def\Ie{\emph{I.e}\onedot}
\def\cf{\emph{c.f}\onedot} \def\Cf{\emph{C.f}\onedot}
\def\etc{\emph{etc}\onedot} \def\vs{\emph{vs}\onedot}
\def\wrt{w.r.t\onedot} \def\dof{d.o.f\onedot}
\def\etal{\emph{et al}\onedot}
\makeatother
Have you tried using the xspace package?
Example macro:
\def\etc{etc.\#\xspace}
Some tests:
Cat, dog, \etc. And so on. \\
Cat, dog, \etc! And so on. \\
Cat, dog, \etc, and so on. \\
Cat (dog, \etc). And so on. \\
Produces:
From the documentation:
The xspace package provides a single
command that looks at what comes after
it in the command stream, and decides
whether to insert a space to replace
one "eaten" by the TeX command
decoder.
A technical challenge! We can avoid the problem of letters after spaces by looking at the catcode of the next character and seeing whether or not it is a letter; this can be done with the Latex3's expl3 macro \peek_charcode:NTF (my first expl3 code!):
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\newcommand\latinabbrev[1]{
\peek_meaning:NTF . {% Same as \#ifnextchar
#1\#}%
{ \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
#1.\# }%
{#1.\#}}}
\ExplSyntaxOff
%Omit final dot from each def.
\def\eg{\latinabbrev{e.g}}
\def\etal{\latinabbrev{et al}}
\def\etc{\latinabbrev{etc}}
\def\ie{\latinabbrev{i.e}}
\begin{document}
Maybe a list, \eg, a, b, c, and d. Which is to say (\ie) a, b, \etc. Consider Knuth, \cf The TeXbook.
\end{document}
Jukka's advice I think is sound, though: I'd say the problem Will works around with his \etc macro we should see as a bug in Tex's implementation of double spacing (Will Robertson should ask for his cheque): if you know the bug is there, you can workaround it directly by putting in \# in cases such as ".)", or you can have tricky code that means you don't have to think in this case, but you have added complexity to the way you typeset which is not going to work for you with the next unexpected glitch, one you probably have introduced yourself.
Postscript Previous version fixed, thanks to Joseph Wright noticing a stupid error at tex.stackexchange.com.
All LaTeX commands eliminate space after them. If you want a space, you need to escape it:
\etc\ and more
This is necessary, because you need to be clear where the command name ends. \etcno space cannot be correctly interpreted.
I know one of LaTeX's bragging points is that it doesn't have this Microsoftish behavior. Nevertheless, it's sometimes useful.
LaTeX already adds an extra space after you type a (non-backslashed) period, so it should be possible to make it automatically capitalize the following letter as well.
Is there an obvious way to write a macro that does this, or is there a LaTeX package that does it already?
The following code solves the problem.
\let\period.
\catcode`\.\active
\def\uppercasesingleletter#1{\uppercase{#1}}
\def.{\period\afterassignment\periodx\let\next= }
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi}
First. second.third. relax.relax. up
\let\period. save period
\catcode\.\active make all periods to be active symbol (like macro).
\def\uppercasesingleletter#1{\uppercase{#1}} defines macro \uppercasesingleletter to make automatically capitalize the following letter.
\def.{\period\afterassignment\periodx\let\next= } writes saved period and checkes the next symbol.
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi} If the next letter is a space then \uppercasesingleletter is inserted.
ages ago there was discussion of this idea on comp.text.tex, and the general conclusion was you can't do it satisfactorily. satisfactory, in my book, involves not making characters active, but i can't see how that could work at all.
personally, i would want to make space active, and have it then look at \spacefactor and \MakeUppercase the following character if the factor is 3000.
something like
\catcode\ \active % latex already has a saved space character -- \space
\def {\ifhmode% \spacefactor is invalid
% (or something) in vertical mode
\ifnum\spacefactor<3000\else% note: with space active,
% even cs-ended lines need %-termination
\expandafter\gobbleandupper\fi}%
\def\gobbleandupper#1{\def\tempa{#1}\def\tempb{ }%
\ifx\tempa\tempb% can''t indent the code, either :-(
% here, we have another space
\expandafter\gobbleandupper% try again
\else\space% insert a "real" space to soak up the
% space factor
\expandafter\MakeUppercase\fi}%
this doesn't really do the job -- there are enough loose ends to knit a fairisle jumper. for example, given that we can't rely on \everypar in latex, how do you uppercase the first letter of a paragraph?
no ... however much it hurts (which is why i avoid unnecessary key operations) we need to type latex "properly" :-(
I decided to solve it in the following way:
Since I always compile the LaTeX code three times before i okular the result (to get pagination and references right), I decided to build the capitalization of sentences into that process.
Thus, I now have a shell script that calls my capitalization script (written in CRM114) first, then pdflatex three times, and then okular. This way, all the stuff happens as the result of a single command.
The listings package supports line breaks inside lstlisting environment. But it doesn't produce automatic line breaks for lstinline environment. For example, in the following paragraph the first line flows out of the margins:
The parameters \lstinline|base_rmr_brain|, \lstinline|base_rmr_fat|, and \lstinline|baseline_basal_rmr_of_lean_tissues| are metabolic rates of brain, fat, and lean tissues in kcal/(kg*day). The parameter \lstinline|mass_brain| denotes the mass of the brain in gram.
Is there any solution for this problem?
The literate feature of listings could be helpful, e.g. to introduce linebreaks at underscores:
\lstset{
literate={\_}{}{0\discretionary{\_}{}{\_}}%
}
I'm just learning latex, so this may be trivial to some of you.
I went through a few tutorials but they all seem to cover the same things.
I'm writing a big report - calculation all the way (and it has to be neat, because it's part of the documentation). It consists of a frame around the page (15mm margins), and 3 columns inside it: in the left column (3cm wide) are references from where the equation came from (e.g. "ABS 3-2-7"), in the middle is the calculation and in the right is the accepted value (5cm wide). It is a standard way of doing things, so I don't have a choice over the layout.
Now, I don't understand, how would I go in creating such layout ? The frame with columns has to appear on every page. How to accomplish that ?
I've never seen such a document so I'm not sure how to ease the creation.
And second, how do I rename things that are in english language in document classes ? For example, "article" class, I have "References" and I need to have "Literatura".
Is there a way to rename it without touching .cls file?
For your first problem, look at the longtable package (available at ctan.org if you haven't already got it installed)
The problem with using tabular is it won't work as you want across pages.
As far as the second problem, it will depend on the environment and the document type, but typically you'll have to renew a command.
For example, add to the preamble \renewcommand\refname{Literatura} for the article class to do what you were asking for. If I recall correctly it is bibname for books.
Table design in LaTeX has not been made very easy. I would use tabbing rather than tabular and draw the lines manually to keep things simple. A downside is that you don't get any automatic sizing of the table cells, but since your format is fixed, I would consider it a good thing (i.e., if text overflows, you notice it and get to fix it yourself, and your table doesn't accidentally get stretched into the margins). If you use multiple tables like this in your document, try packaging the commands with \newenvironment.
\documentclass{article}
\usepackage[margin=15mm]{geometry}
\usepackage{amsmath}
\usepackage{calc}
\newlength{\tableheight}
\setlength{\tableheight}{20cm} % how high to draw the lines of the table
\newlength{\rulethickness}
\setlength{\rulethickness}{1pt} % how thick lines to draw
\newcommand{\verticalline}{\smash{\rule[-\tableheight]{\rulethickness}{\tableheight}}}
\newlength{\myindent}
\setlength{\myindent}{3mm} % how much to indent each column
\newlength{\leftcolumn}
\setlength{\leftcolumn}{3cm-\myindent}
\newlength{\midcolumn}
\setlength{\midcolumn}{\textwidth-3cm-5cm-\myindent-\rulethickness}
\newlength{\rightcolumn}
\setlength{\rightcolumn}{5cm-\myindent}
\begin{document}
\begin{tabbing}
% first set the tab stops
\hspace*{\myindent}\=\hspace{\leftcolumn}\=%
\hspace{\myindent}\=\hspace{\midcolumn}\=%
\hspace{\myindent}\=\hspace{\rightcolumn}\=\kill
% then draw the lines
\rule{\textwidth}{\rulethickness}\\[-\baselineskip]
\smash{\rule[-\tableheight]{\textwidth}{\rulethickness}}\\[-\baselineskip]
\verticalline\>\>\verticalline\>\>\verticalline\>\>\verticalline\\
% Now start the table: indent the first column with \>
\>ABS 3--2--7
% ... and each additional column with \>\>
\>\> $\iint_{-\infty,-\infty}^{\infty,\infty} e^{-x^2-y^2}\, dx\,dy$
\>\> 2.507
% End each line with \\, add e.g. [2pt] to get 2pt extra space if required
\\[2pt]
% here's another line:
\>ABS 3--2--8 \>\> $\displaystyle\sum_{k=0}^n k^2$ \>\> $\frac12 n(n+1)$ \\
% etc. Be careful not to overflow the table - there's no automatic check for that.
\end{tabbing}
\newpage % also remember to start a new page after the table
\end{document}
To change the fixed names, see this FAQ, or possibly this one if you are using babel.
In this case you probably want to use the tabular environment to generate the three columns (or as simon notes longtable if your report-thingy runs longer than one page). Something like:
\framebox{
\centering
\begin{tabular}{p{3cm}|p{\specialwidth}|p{5cm}}
Ref 1-0-0 & 1.2345 & 1.2346 \\
Ref 1-0-1 & 2.3456 & 2.3454 \\
...
\end{tabular}
}
You'll note that I've used paragraph formatted columns (the p{<length>} formatting specifiers), and stuck a frame around it with \framebox.
You can either compute \specialwidth by hand, or calculate it:
\newlength{\specialwidth}
\setlength{\specialwidth}{\textwidth}
\addtolength{\specialwidth}{-10cm} % extra room for the seperators...
I can't help you on the internationalization issue...