Text exceed from cover page, how to solve it? - latex

I have brought the title, which is a bit long sentence in cover page.
However, it exceeds the page width, how to correct it? Thanks
\vspace{30mm} \centerline{{\bf Title BLAH Blah}}

You could try using the center environment, as it allows natural wrapping at within the text block:
\begin{center}
\bfseries
Lorem ipsum dolor sit amet, consectetur adipiscing elit \ldots
\end{center}
Note the use of \bfseries rather than \bf:
Does it matter if I use \textit or \it, \bfseries or \bf, etc
Will two-letter font style commands (\bf , \it , …) ever be resurrected in LaTeX?

Related

insert image in latex

I tried to insert image in latex. I first uploaded images to sidebar of overleaf. And then I used such code
We still first focus on totally random dataset.\\
\begin{figure}[h]
\centering
\includegraphics[width=0.7\textwidth]{aab.png}
\caption{aab\label{thename}}
\end{figure}
Then we focus on partially random dataset.\\
\begin{figure}[h]
\centering
\includegraphics[width=0.7\textwidth]{abb.png}
\caption{abb\label{thename}}
\end{figure}
At last we look at true dataset.
\begin{figure}[h]
\centering
\includegraphics[width=0.7\textwidth]{aba.png}
\caption{aba\label{thename}} \end{figure}
And then But what I got is
There images are all in wrong positions, they all appear after texts, but they are supposed to be inserted between the texts. Where the issue comes from?
\begin{figure}[h!]instead of \begin{figure}[h] would be the best choice. But you can also use \begin{figure}[H] but you need to add the float package.
Please see:
https://www.overleaf.com/learn/latex/Positioning_images_and_tables, the section under figure environment educates the different parameters and their meaning under figure environment.
The figure environment is meant to float, which means that latex will find a good place for it. You should write your text in such a way that you expect specific positions for the images. Instead you can references them by their number in the text. This method works best if you have a bit more text than in your example, so I added a bit of random text in the example below so you can see how this works.
If you don't want this, you shouldn't use a figure environment. instead you could use the \captionof macro to add captions to your non-figure images.
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\section{The latex way:}
At first, we focus on a totally random dataset, depicted in figure \ref{thenamea}. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{example-image-duck}
\caption{aab\label{thenamea}}
\end{figure}
After that we focus on partially random dataset as shown in figure \ref{thenameb}. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{example-image-duck}
\caption{abb\label{thenameb}}
\end{figure}
At last we look figure \ref{thenamec} which is the true dataset. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{example-image-duck}
\caption{aba\label{thenamec}}
\end{figure}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\clearpage
\section{No floats}
We still first focus on totally random dataset.
{
\centering
\includegraphics[width=0.65\textwidth]{example-image-duck}
\captionof{figure}{aab\label{thenameaa}}
}
Then we focus on partially random dataset.
{
\centering
\includegraphics[width=0.65\textwidth]{example-image-duck}
\captionof{figure}{abb\label{thenamebb}}
}
At last we look at true dataset.
{
\centering
\includegraphics[width=0.65\textwidth]{example-image-duck}
\captionof{figure}{aba\label{thenamecc}}
}
\end{document}

In TeX, how do I define the label style for compactenum globally?

I have a couple of compactenum elements in my document. I would like define color and type for all labels in a more elegant way than this:
\begin{compactenum}[label=\textcolor{black}{\arabic*.}]
\item lorem
\item ipsum
\item dolor
\end{compactenum}
\begin{compactenum}[label=\textcolor{black}{\arabic*.}]
\item sit
\item amet
\end{compactenum}
How do I set it globally the most elegant way? Is there a way where I can define the behavior for compactenum without using [...] at all?
What you need is \setdefaultenum{\color{black} 1.}{}{}{}. It will set your outer label to be black arabic label. For more information, refer to paralist documentation Here's a MCVE:
\documentclass{article}
\usepackage{paralist,xcolor}
\setdefaultenum{\color{black} 1.}{}{}{}% What you need!
% The 1. is the equivalent of \arabic*.
% The other {}{}{} refer to the list levels,
% i.e. {second level}{third level}{fourth level}
\begin{document}
\begin{compactenum}
\item lorem
\item ipsum
\item dolor
\end{compactenum}
\end{document}

align-like environment in LaTeX for lines of texts

I am looking for a LaTeX environment, that is capable of formatting given paragraph(s) with a slight indentation and increasing line counters within parenthesis, e.g.:
(1) Lorem Ipsum
(2) Dolor Sit
These numbers should continue to increase throughout the document, i.e. there should be no number used twice. It would behave almost like the align environment- including the possibility to \ref to individual lines, except that I do not wish to use it for math but rather for text snippets.
Unfortunately, I am not that LaTeX savvy, so I cannot really define such an environment myself.
Is this what you're looking for?
\documentclass{article}
\usepackage{lipsum} % just for blind text
\usepackage{enumitem}
\newlist{masterlist}{enumerate}{1}
\setlist[masterlist]{label=(\arabic*),resume}
\begin{document}
\lipsum[1]
\begin{masterlist}
\item foo
\item bar
\end{masterlist}
\lipsum[2-3]
\begin{masterlist}
\item baz
\item boo
\end{masterlist}
\end{document}
In fact you want an enumerate list with number in a non default presentation. An easy way for this is the enumerate package:
\documentclass{article}
\usepackage{enumerate}
\begin{document}
\begin{enumerate}[(1)]
\item test1
\item test2
\end{enumerate}
\end{document}
You could use the align environment (or other math-based environments) and typeset your text using \text{...}. Example:
\begin{equation}\label{mylabel}
\text{Numbered like an equation, typeset like text.}
\end{equation}
Beware, though, that this is only suitable for short snippets of text, since you are, after all, inside a math environment, so there's no automatic line wrapping.

LaTeX/Beamer, column environment. Horizontal alignment of overlays

I am trying to prepare a presentation using beamer. I want to have two columns that walkthrough some algebraic manipulations. On the left an explanation of the steps taken, on the right the results.
\documentclass{beamer}
\begin{document}
\begin{frame}[t]
Not in a column
\begin{columns}[t]
\begin{column}{0.5\textwidth}
\only<2->{Some text}
\only<3->{
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
}
\end{column}
\begin{column}{0.5\textwidth}
\only<2->
{
\begin{equation}
E = mc^2
\end{equation}
}
\only<3->
{
\begin{equation}
F = ma
\end{equation}
}
\end{column}
\end{columns}
\end{frame}
\end{document}
And here's some LaTeX which does that (with junk words and equations). When this is compiled the text and maths are not aligned with each other. I wouldn't really expect them to be either as LaTeX will position the text in each column individually, not caring about the other frames.
Does anyone have any ideas on how to achieve the result I am after. I'm not committed to the columns at all, but I am committed to the equation numbers.
The preferred way to get aligned equations with numbering is amsmath package's align environment. See its documentation for help with that. It's quite simple, something like:
\begin{align}
f(x) & = \cos^2 x \\
g(x) & = \sin^2 x
\end{align}
There are a lot of variations trying to cover most conceivable equation alignment needs (again, check out the documentation).
As for your two-column proof format, I'm not as sure about the best way. A quick and dirty way would be to add it as a second column within the environment, something like:
\begin{align}
f(x) & = \cos^2 x & \text{this is the first function} \\
g(x) & = \sin^2 x & \text{this is the second function}
\end{align}
but this is no good for multi-line explanation, and puts the numbering to the right of the text. I'll try and think of a way (one that doesn't involve a lot of custom-defined environments, since surely someone's done this before).
Edit: As a starting point, this [sort of] works:
You can't do any alignment within the align environment (the & confuses things), and there are some vertical alignment issues - the align environment pads itself above and below, and the text in the right-hand cell. Maybe it's heading in a good direction, though!
\begin{tabular}{p{3 in}|l}
\begin{align} f(x) = \sin^2 x \end{align} &
this is the first equation \\
\begin{align} g(x) = \cos^2 x \end{align} &
this is the second equation
\end{tabular}
Usually you'd use amsmath's align or align* environment, but unfortunately it doesn't play nicely with beamer (for fundamental reasons that nobody wants to fix).
The Beamer user guide has a section on this at page 106 that does exactly what you've done. Apparently there's a workaround described in that document too.

Centering a table wider than the text column

I'm including a table in my LaTeX document and the centering works fine if the table isn't wider than the text column above it, but when the table is wider, the left side of the table sticks to the left side of the text column, and the additional width of the table is on the right side of the page, how can I center the table?
I'd recommend trying the chngpage package.
\documentclass{article}
% allows for temporary adjustment of side margins
\usepackage{chngpage}
% provides filler text
\usepackage{lipsum}
% just makes the table prettier (see \toprule, \bottomrule, etc. commands below)
\usepackage{booktabs}
\begin{document}
\lipsum[1]% just a paragraph of filler text
\medskip% adds some space before the table
\begin{adjustwidth}{-1in}{-1in}% adjust the L and R margins by 1 inch
\begin{tabular}{ll}
\toprule
Sequence & Wide column \\
\midrule
First & Vestibulum porta ultricies felis. In nec mi. \\
Second & Nam vestibulum auctor nibh. In eleifend,
lacus id tristique ullamcorper, mauris urna convallis elit. \\
Third & Ut luctus nisi quam lobortis magna. Aenean sit amet odio
et sapien rutrum lobortis. \\
Fourth & Integer dictum accumsan purus. Nullam erat ligula,
dictum sed, feugiat nec, faucibus id, ipsum. \\
\bottomrule
\end{tabular}
\end{adjustwidth}
\medskip% adds some space after the table
\noindent\lipsum[2]% just a paragraph of filler text
\end{document}
The documentation for the chngpage package is located at the bottom of the chngpage.sty file. I've pulled out the docs for the adjustwidth environment:
Within an adjustwidth environment
the left and right margins can be
adjusted. The environment takes one
optional argument and two required
length arguments:
\begin{adjustwidth}[]{leftmargin}{rightmargin}
A positive length value will increase the relevant margin
(shortening the text lines) while a
negative length value will decrease
the margin (lengthening text lines).
An empty length argument means no
change to the margin. At the end of
the environment the margins revert to
their original values.
For example, to extend the text
into the right margin:
\begin{adjustwidth}{}{-8em}
Any appearance of the optional
argument (even just []) will cause the
values of the margins to switch
between odd and even pages.
If the document is being set
twosided it might be advantageous to
have any wider text extending into the
outside margin. This could be done via
the optional argument, as:
\begin{adjustwidth}[]{}{-8em}
To have the adjusted text
horizontally centered with respect to
any surrounding text, the margins
should be adjusted equally:
\begin{adjustwidth}{-4em}{-4em}
Latex: Centering table larger than textwidth
Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth.
% allows for temporary adjustment of side margins
\usepackage{chngpage}
\begin{table}
\begin{adjustwidth}{-.5in}{-.5in}
\begin{center}
\begin{tabular}{|c|}
\hline
And here comes a very long line. And here comes a very long line. And here comes a very long line. \\
\hline
\end{tabular}
\caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. }
\label{myTable}
\end{center}
\end{adjustwidth}
\end{table}
If you're using a \table float, the \begin{adjustwidth} ... \end{adjustwidth} has to be contained inside it.
In figures, the figure environment must contain the adjustwidth env.. Furthermore, caption should be left outside of this environment to align with the overall figure's width:
\begin{figure}[h]
\begin{adjustwidth}{-1in}{-1in}% adjust the L and R margins by 1 inch
\centering
\includegraphics[scale=0.44]{res/sth.png}
\end{adjustwidth}
\caption{sth}
\label{fig:sth}
\end{figure}
Are you using a multi-column document? I so, consider the table* variant environment.
In a single column environment your options run to:
Increase the textwidth. But the default margin were choosen for good ergonomic reasons, so this is to be discouraged beyond a minimal tweaking.
Reduce the text size in the table (i.e. \small or even \footnotesize inside the tabular environment). Again, this is less than optimal.
Use the rotating package as suggested in the link Stephan202 gave. I used this for a couple of very large tables in my dissertation (with only the p positioning options) and it came out very nicely.

Resources