Wrap Sentences in Tabular Environment [closed] - latex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm using the tabular environment in Latex (Overleaf) and would like my text to wrap automatically and be justified. The closest I can get to this is to use the \\ syntax. This is laborious; further, I would like to have justified text, like the rest of my document. I am using a snippet that I found here, but it does not incorporate automatic wrapping and justified text. My minimum working example follows:
\documentclass[11pt,fleqn]{book}
\usepackage{import}
\usepackage{fancyhdr}
\fancyhf{}
\cfoot{\thepage}
\pagestyle{fancy}
\usepackage{soul}
\usepackage[utf8]{inputenc}
\usepackage{subfiles}
%\bibliographystyle{aea}
\usepackage[backend=biber,style=authoryear,sorting=nyvt]{biblatex}
\addbibresource{newbib3.bib}
\begin{document}
\noindent\textbf{Analysis of Editing}\\
\noindent{Substantive}: 0, -2.\\
Further: the, mighty.\\
\begin{tabular}{#{}l#{\ }l}
Value Added: & Yes, I want the benefit of using the tabular environment.\\
& No, because I would like this text to wrap automatically (instead of extending out continuously) and to be justified.
\end{tabular}
\end{document}
Which produces the following:
Analysis of Editing
Substantive: 0, -2.
Further: the, mighty.
Value Added: Yes, I want the benefit of using the tabular environment.
No, because I would like this text to wrap automatically (instead of extending out continuously) and to be justified.

You could either use a column of fixed width, e.g. p{5cm} or a tabularx that will automatically adjust the width of the X columns to fill the desired with.
Unrelated note: please do not abuse \\ for line breaks outside of tables
\documentclass[11pt,fleqn]{book}
\usepackage{import}
\usepackage{fancyhdr}
\fancyhf{}
\cfoot{\thepage}
\pagestyle{fancy}
\usepackage{soul}
\usepackage[utf8]{inputenc}
\usepackage{subfiles}
%\bibliographystyle{aea}
\usepackage[backend=biber,style=authoryear,sorting=nyvt]{biblatex}
\addbibresource{newbib3.bib}
\usepackage{tabularx}
\begin{document}
\noindent\textbf{Analysis of Editing}
\noindent{Substantive}: 0, -2.
Further: the, mighty.
\begin{tabularx}{.953\linewidth}{#{}l#{\ }X}
Value Added: & Yes, I want the benefit of using the tabular environment.\\
& No, because I would like this text to wrap automatically (instead of extending out continuously) and to be justified.
\end{tabularx}
\end{document}

Related

Koma scrbook seems not to include BCOR

The proof copies of a book laid out with KOMA scrbook show that the inner margins are too narrow. I had BCOR set to 10mm and want to increase them, but my experiments with BCOR set to 20mm show that the layout is the same independent what BCOR value I set. Here my MWE:
\documentclass{scrbook}
\KOMAoptions{paper=
128.5mm:198.4mm, %(5,06" x 7,91") %ziel
BCOR=20mm,
twoside,
headinclude=false, footinclude=false,
headings=normal,
titlepage=true,
% draft=true,
DIV=9, %ziel kleines buch
fontsize=12pt,
}
\usepackage[german]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage[a4,axes,cross,pdftex,center]{crop}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{ Philosophie}
some text
\lipsum
\lipsum
\end{document}
What is wrong?
My real question is: how can I just move the text area on both pages to the outside (i.e. making the gutter wider) without changing the text area size (and thus preserve line breaks)?
I found a hint in some other questions answered before and the problem was caused by the interaction between the KOMA script and the geometry package. Using the geometry package recalculates the page layout and overwrites the one calculated by scrbook including the BCOR value. This can be avoided when adding the option pass to geometry as in
`\usepackage[pass]{geometry}`.
In general the interaction between the layout calculated by KOMAscript and other package can lead to surprises. The discussion in https://tex.stackexchange.com/questions/182821/div-and-bcor-setting-in-koma-best-practices/183839 is very useful.

Writing a CV in Latex [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
I am trying to write a CV in Latex, but now I am stuck. Since I want to learn Latex, I don't really want to just use a template.
I am thinking about one page divided in to columns/minipages:
Left column: an image + contact information etc.
Right Column: Education, experience, volunteer work etc.
Tried minipages and columns, but the image is destroying the whole format... Tried to use parts from templates, which worked fine, i.e. secsty etc. See example under.
Not a specific question, but hope someone has a good idea for how to make something out of this idea :)
Example:
%Preamble
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{geometry}
\geometry{a4paper, total={170mm,257mm}, left=10mm, top=10mm}
\pagestyle{empty}
%%% Custom sectioning (sectsty package)
\usepackage{sectsty}
\sectionfont{\usefont{OT1}{phv}{m}{n}\sectionrule{0pt}{0pt}{-10pt}{1pt}}
\subsectionfont{\usefont{OT1}{phv}{m}{n}}
%Document
\begin{document}
\begin{minipage}[250mm]{0.4\linewidth}
\includegraphics{image.png}
Date of birth:
Phone:
Email:
\end{minipage}
\begin{minipage}[250mm]{0.65\linewidth}
\part*{Name}
\section*{EDUCATION}
\section*{EXPERIENCE}
\end{minipage}
\end{document}
It is great to see that you don't simply copy one of the existing templates, but want to learn some latex instead.
Some comments about your code:
if you want the minipages besides each other to emulate columns, their combined sum has to be equal or smaller than the linewidth. In your example 0.4+0.65= 1.05, so they won't fit in one line. In fact I would make them a bit smaller and add a \hfill between to get a bit of space between them
to make sure each minipage is only as wide as you specified, I would add the [width=\linewidth] option to the image. This will automatically scale the image correctly
if you want both minipages in one line, don't leave an empty line between them. In latex and empty line in the source code is interpreted as a paragraph break, thus forcing your second minipage in a new line
To get a better vertical alignment of the image, I would remove the optional height argument from the minipage and let tex determine how high your minipages are and add the options [T] and [b] respectively to determine the vertical alignment
this is more a design question: at the moment your page geometry is highly asymmetric. You can visualise this by adding showframe to your geometry options, e.g. \geometry{a4paper, total={170mm,257mm}, left=10mm, top=10mm,showframe}. Are you sure this is a good choice for a CV?
%Preamble
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{geometry}
\geometry{a4paper, total={170mm,257mm}, left=10mm, top=10mm}
\pagestyle{empty}
%%% Custom sectioning (sectsty package)
\usepackage{sectsty}
\sectionfont{\usefont{OT1}{phv}{m}{n}\sectionrule{0pt}{0pt}{-10pt}{1pt}}
\subsectionfont{\usefont{OT1}{phv}{m}{n}}
%Document
\begin{document}
\noindent
\begin{minipage}[T]{0.4\linewidth}
\includegraphics[width=\linewidth]{example-image-duck}
Date of birth:
Phone:
Email:
\end{minipage}%
\hfill
\begin{minipage}[b]{0.55\linewidth}
\part*{Name}
\section*{EDUCATION}
\section*{EXPERIENCE}
\end{minipage}
\end{document}

Start new section at top of page, not below a figure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
When I use more than one figure per section in LATEX, I am no longer able to dictate that the section number start just after a page break. I've been struggling with this for a while. If there are any LATEX wizards out there, your help would be much appreciated.
In the file referenced below, it is section 2 that I am struggling with. The final document is much, much longer than this and this problem happens several times, but I thought for the sake of clarity I would create a simpler version that still exhibits the problem.
zip file containing everything
\documentclass{article}
\usepackage{graphicx}
\usepackage{placeins}
\widowpenalty=2000
\clubpenalty=2000
\begin{document}
\section{}
\begin{figure} [h]
\center
\includegraphics[width=12cm]{Figure}
\label{fig:example}
\end{figure}
\FloatBarrier
My goal is to have section 2 start on a new page.
$$\\$$
\begin{figure} [h]
\center
\includegraphics[width=14cm]{Figure}
\label{fig:example}
\end{figure}
\newpage
\pagebreak [4]
$$\\$$
\section{}
\begin{figure} [h]
\center
\includegraphics[width=14cm]{Figure}
\label{fig:example}
\end{figure}
This is the body text for section 2.
\end{document}
Figure.jpg
Have you tried \clearpage instead of \newpage?

How to center LaTeX xtable (And Figure) output in full text width

This is a follow-up to a question I posted earlier (How to center LaTeX xtable output in full text width).
I realize that my MWE from this previous post was incomplete. In an effort to make it as minimal of an example as possible, I did leave out something that ended up conflicting. Hence, here, I am posting the issue more fully.
I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw:
\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{geometry}
\usepackage{pgffor}
\usepackage{calc}
\usepackage{enumitem}
\usepackage{microtype}
\usepackage{tabularx}
%\usepackage{floatrow}
\begin{document}
<<include=FALSE>>=
library(ggplot2)
library(xtable)
#
\begin{fullwidth}
\makeatletter\setlength\hsize{\#tufte#fullwidth}\makeatother
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:10,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))
print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
#
\end{fullwidth}
<<echo=FALSE,results='asis'>>=
fnameO <<- "plot.pdf"
pdf(paste0("./",fnameO),width=6,height=7)
print(qplot(hp, mpg, data=mtcars, main="Scatterplots of MPG vs. Horsepower", xlab="Horsepower", ylab="Miles per Gallon"))
{dev.off();invisible()}
#
\begin{fullwidth}
\makeatletter\setlength\hsize{\#tufte#fullwidth}\makeatother
\begin{figure}[!ht]
\includegraphics[width=\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R. It compares the horsepower with the miles per gallon. It uses the qplot function from ggplot2.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
\end{document}
This is the output:
I am desiring to have both the table and the figure centered (across the whole page). As shown above, I am successfully able to get the table centered (thanks to advice from a user in my previous post).
However, I am unable to get the figure centered across the whole page with the caption below it. Instead, likely due to the document class I am using (tufte-handout), the figure itself is in the non-margin area, and its caption is in the margin area.
For starters, I uncommented the \usepackage{floatrow} in the code, in an attempt to force the figure caption to be below the figure instead of to the right of it. This lead to an output as such (where both the table and figure are undesirably on the left side instead of centered, but the figure caption is indeed below the figure):
My question is: How can I center both the table and figure (with the caption below it), so that the output would look more like this?:
Thank you.
As a crude hack, you could simply modify the figure environment of your MWE to use the original \caption command:
\begin{fullwidth}
\begin{figure}[!ht]
\makeatletter\setlength\hsize{\#tufte#fullwidth}\setlength\linewidth{\#tufte#fullwidth}\let\caption\#tufte#orig#caption\makeatother
\includegraphics[width=\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R. It compares the horsepower with the miles per gallon. It uses the qplot function from ggplot2.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
...or, for a bit smaller figure that is centered on the page:
\begin{fullwidth}
\begin{figure}[!ht]
\makeatletter\setlength\hsize{\#tufte#fullwidth}\setlength\linewidth{\#tufte#fullwidth}\let\caption\#tufte#orig#caption\makeatother
\centering
\includegraphics[width=.4\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
If you find the original \caption command lacking and if none(!) of the floats in your document need to use tufte captions you can overwrite the \caption command using something like \usepackage[labelfont=bf,compatibility=false]{caption}.

Make code in LaTeX look *nice* [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm currently writing a project report, and to explain the slightly crazy un-intuitive code that I've used I need to put lots and lots of short excerpts of example code in.
How I can get code into LaTeX that:
looks nice
doesn't go off the side of the page if the line's too long (list lstlisting or verbatim)
is preferably inline with the rest of the text
EDITED (Figured I'd add the settings so people don't have to try and figure them out themselves (taken from wikibooks (link further down) and edited for niceness))
Nice settings:
\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C++, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)} % if you want to add a comment within your code
}
\begin{lstlisting}
!!code!!
\end{lstlisting}
An example of these settings:
The listings package is quite nice and very flexible (e.g. different sizes for comments and code).
It turns out that lstlisting is able to format code nicely, but requires a lot of tweaking.
Wikibooks has a good example for the parameters you can tweak.
For simple document, I sometimes use verbatim, but listing is nice for big chunk of code.

Resources