Easiest way to center tables and other elements? - latex

What is the best way to make things center properly? Once I start messing around with tables, things either start shifting left or right, destroying the balance. How can make it so everything is always centered?
Right now this will lead to the table being messed up, and have the right edge go off the screen. What can I do?
Here's most of the code, I cut out a lot of the useless functions, since they are all almost the same. Its for making Use Cases for school, since we got to do about 40 of these for a project.
\documentclass[10pt, a4paper]{article}
\usepackage{booktabs}
\begin{document}
\newcommand{\UCStart}[2]{
\newpage
\subsection[UC.#1]{UC.#1}
\begin{tabular}{|l|m{4in}|c|}
\hline
\textbf{UC.#1}
& \textbf{#2}
& \textbf{Traceability} \\ \hline
}
\newcommand{\UCDesc}[2]{
\textbf{Description}
& #1
& #2 \\ \hline
}
\newcommand{\UCActors}[2]{
\textbf{External Actors}
& #1
& #2 \\ \hline
}
% Snip... 40 odd more functions %
\newcommand{\UCEnd}{
\end{tabular}
}
\begin{table}[!ht]
\setlength{\extrarowheight}{2pt}
% UC 1
\UCStart{01}{Administrator Starts Server}
\UCDesc{This describes the process of the administrator starting the server}{\space}
\UCActors{Administrator}{\space}
\UCRelated{UC.02}{\space}
\UCPre{Server is not running}{\space}
\UCTrigger{Administrator wants to start the server}{\space}
\UCSeq{
\begin{enumerate}
\item Administrator boots up hardware
\item Administrator starts Administrator console
\item Administrator logins into Administrator account with the corresponding password
\item Administrator clicks start
\end{enumerate}
}{\space}
\UCPost{Conditions that must be true, in order for the use case to finish}{\space}
\UCAltSeq{
\textbf{Alternative Use Case 01} \newline
\begin{itemize}
\item UC.01.ALT.01
\item If administrator fails authentication in step 3
\begin{enumerate}
\item Notify administrator of failed authentication
\end{enumerate}
\end{itemize}
}{\space}
\UCNonFunc{ ??? }{\space}
\UCComments{ Comments Go Here }{\space}
\UCEnd
\end{table}
\end{document}

I can't compile your example due to several errors, and I'm not sure what you mean by "the best way to make things center properly". As a kind of crystal ball-type answer, is this what you're looking for?
\documentclass[10pt,a4paper]{article}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\begin{tabular}{
| >{\centering\arraybackslash }p{4cm} |
>{\centering\arraybackslash }p{6cm} |
}
\hline
some centred text in cells & some more centred text in cells \\
\hline
centred text in cells & more centred text in cells \\
\hline
\end{tabular}
\end{table}
\end{document}

It is difficult to see what the problem is when we can't compile your example.
Looking through the code you provided, a table may not actually be appropriate in this situation. Instead, you might try something like the following:
\documentclass[10pt,a4paper]{article}
\begin{document}
\subsection{Administrator Starts Server}
\paragraph{Description:} This describes the process of the adminsitrator starting the server.
\paragraph{Actors:} Administrator
\paragraph{Preconditions:} Server is not running.
\paragraph{Sequence:}
\begin{enumerate}
\item Administrator boots up hardware
\item Administrator starts Administrator console
\item Administrator logins into Administrator account with the corresponding password
\item Administrator clicks start
\end{enumerate}
\end{document}
In the example you provided, I don't see that you ever put any text in the "Traceability" column. To mimic this column, you could either use \marginpar{my text} to put text in the margin, or you could use blahblah\hfill{}my text to right-align text on the same line as "blahblah". If you want the traceability text to be right-aligned and on its own line, use \begin{flushright} my text \end{flushright}.
If this doesn't help solve your problem, please provide us with a minimal example that compiles and demonstrates the problem.

Related

How can one start an \item with a math align environment?

In latex, I need to start an item in an enumerate list with an align* environment, but this environment starts with a new line, leaving an ugly empty space.
What I'm trying to achieve:
e^{ix}=cos x+i sin x
e^{i\pi} = -1
e^{i\pi}+1=0
What I'm trying:
\begin{enumerate}
\item \begin{align*}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{align*}
\end{enumerate}
Is there some other environment for this?
(I know that it is not recommended to start an item with a displayed math formula, but in this case I need to.)
As a workaround:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item \hfill$\begin{aligned}[t]
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{aligned}$\hfill\mbox{}
\end{enumerate}
\end{document}
A hack similar to the one in the accepted answer: the environment matrix needs no package to work and has no visible delimiters:
\documentclass{article}
\begin{document}
\begin{enumerate}
\item $\begin{matrix}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{matrix}$
\end{enumerate}
\end{document}
The output seems to me similar to the one you wanted to achieve:

Try to move the table to the left, but failed

I was trying to reposition my table a bit left to the page, so I try \hskip -2cm or \hspace{-2cm} But non of these can move the table and here is my code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}
\usepackage{indentfirst}
\setlength\extrarowheight{2pt}
\title{}
\author{}
\begin{document}
\maketitle
\section{Introduction}
\section{Data Summary}
\begin{table}[H]
\begin{threeparttable}
\small
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\hskip -2cm
\caption{Summary of numeric variables}
\begin{tabular}{l*{1}{ccccc}}
\hline\hline
&\multicolumn{5}{c}{(1)} \\
&\multicolumn{5}{c}{} \\
& count& mean& sd& min& max\\
\hline
Unemployment Rate & 170& 8.3323& 4.1395& 3.1000& 26.0919\\
log of spending per person for secondary education& 168& 9.0229& 0.4344& 7.6109& 9.9616\\
log of spending per person for teriary education& 165& 9.5241& 0.3967& 8.7797& 10.7478\\
log of exchange rate& 170& 1.0983& 2.0997& -0.4986& 7.0522\\
log of GDP per person& 168& 10.5306& 0.3592& 9.7330& 11.5213\\
log of GDP fixed purchasing power& 165& 27.0045& 1.4905& 23.3668& 30.5051\\
log of GDP growth & 159& 1.2268& 0.7896& -1.7458& 3.0063\\
Long-term interest rate on government bonds& 165& 3.8447& 2.1387& 0.5511& 10.5465\\
Short-term interest rate& 170& 1.7675& 1.9971& 0.0078& 10.3317\\
\hline\hline
\end{tabular}
\begin{tablenotes}
\small
\item Source: OECD (2019), Education at a Glance Database, http://stats.oecd.org
\end{tablenotes}
\end{threeparttable}
\end{table}
\section{Methodology}
\end{document}
and my table looks like this:
and I want to make my table left about a least 1.5cm.
Is there other way to do this?
Having your table project into the margin is not a good style for a layout that is not specifically designed to have additional space in the margins for this. The margin should belong to the reader to easily hold your document, adding notes etc. If there is not enough space things like Fermat's Last Theorem are your fault :)
Instead I suggest to use a tabularx to fit the table into the available space:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}
\usepackage{indentfirst}
\setlength\extrarowheight{2pt}
\usepackage{tabularx}
\usepackage{siunitx}
\title{}
\author{}
\begin{document}
\maketitle
\section{Introduction}
\section{Data Summary}
\begin{table}[H]
\begin{threeparttable}
\small
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\hskip -2cm
\caption{Summary of numeric variables}
\begin{tabularx}{\linewidth}{#{}XS[table-format=3.0]S[table-format=2.4]S[table-format=1.4]S[table-format=-1.4]S[table-format=2.4]#{}}
\toprule
&\multicolumn{5}{c}{(1)} \\\addlinespace
& {count}& {mean}& {sd}& {min}& {max}\\
\midrule
Unemployment Rate & 170& 8.3323& 4.1395& 3.1000& 26.0919\\
log of spending per person for secondary education& 168& 9.0229& 0.4344& 7.6109& 9.9616\\
log of spending per person for teriary education& 165& 9.5241& 0.3967& 8.7797& 10.7478\\
log of exchange rate& 170& 1.0983& 2.0997& -0.4986& 7.0522\\
log of GDP per person& 168& 10.5306& 0.3592& 9.7330& 11.5213\\
log of GDP fixed purchasing power& 165& 27.0045& 1.4905& 23.3668& 30.5051\\
log of GDP growth & 159& 1.2268& 0.7896& -1.7458& 3.0063\\
Long-term interest rate on government bonds& 165& 3.8447& 2.1387& 0.5511& 10.5465\\
Short-term interest rate& 170& 1.7675& 1.9971& 0.0078& 10.3317\\
\bottomrule
\end{tabularx}
\begin{tablenotes}
\small
\item Source: OECD (2019), Education at a Glance Database, http://stats.oecd.org
\end{tablenotes}
\end{threeparttable}
\end{table}
\section{Methodology}
\end{document}
Some other comments:
Try to avoid [H], this is usually a guaranty for bad suboptimal placement of floats. I suggest [htbp] instead
*{1}{ccccc} can be shorted to either ccccc or *{5}{c}
You already load the booktabs package, so I suggest to use \toprule, \midrule and \bottomrule instead of \hline because they have much better spacing around them
instead of manually adding empty lines in the table, I suggest the \addlinespace macro from the booktabs package
With the S column from the siunitx package you can align the numbers by their decimal marker and use actual minus signs instead of cheating with hyphens
you should check the significant figures of your values. If your standard deviation is between 0.3 and 4.1, it makes no sense to give the values with 4 decimal places.

How do I left justify text between enumerates in LaTex?

\begin{enumerate}
\def\labelenumi{\Alph{enumi}.}
\item
The \textbf{Definition} of ``Period of Restoration'' is replaced by
the following:
\begin{enumerate}
\def\labelenumii{\arabic{enumii}.}
\setcounter{enumii}{2}
\item
``Period of Restoration'' means the period of time that:
\begin{enumerate}
\def\labelenumiii{\alph{enumiii}.}
\item
Begins:
\begin{enumerate}
\def\labelenumiv{(\arabic{enumiv})}
\item
72 hours after the time of direct physical loss or damage for
Business Income coverage; or
\item
Immediately after the time of direct physical loss or damage for
Extra Expense coverage;
\end{enumerate}
caused by or resulting from any Covered Cause of Loss at the
described premises; and
\item
Ends on the earlier of:
\begin{enumerate}
\def\labelenumiv{(\arabic{enumiv})}
\item
The day before the opening of the next school term following the
date when, with reasonable speed and similar quality, the
property at the described premises should be repaired, rebuilt
or replaced; or
\item
The date when the school term is resumed at a new permanent
location.
\end{enumerate}
"Period of Restoration" does not include any increased period required due to the enforcement of any ordinance or law that:
I need the last line to line up under b. and it is lining up under (2)
I am getting this:
I believe you need two \end{enumerate} 's after the "The date ... permanent location." line.
\documentclass[]{article}
\begin{document}
\begin{enumerate}
\def\labelenumi{\Alph{enumi}.}
\item
The \textbf{Definition} of ``Period of Restoration'' is replaced by
the following:
\begin{enumerate}
\def\labelenumii{\arabic{enumii}.}
\setcounter{enumii}{2}
\item
``Period of Restoration'' means the period of time that:
\begin{enumerate}
\def\labelenumiii{\alph{enumiii}.}
\item
Begins:
\begin{enumerate}
\def\labelenumiv{(\arabic{enumiv})}
\item
72 hours after the time of direct physical loss or damage for
Business Income coverage; or
\item
Immediately after the time of direct physical loss or damage for
Extra Expense coverage;
\end{enumerate}
caused by or resulting from any Covered Cause of Loss at the
described premises; and
\item
Ends on the earlier of:
\begin{enumerate}
\def\labelenumiv{(\arabic{enumiv})}
\item
The day before the opening of the next school term following the
date when, with reasonable speed and similar quality, the
property at the described premises should be repaired, rebuilt
or replaced; or
\item
The date when the school term is resumed at a new permanent
location.
\end{enumerate}
\end{enumerate}
``Period of Restoration" does not include any increased period required due to the enforcement of any ordinance or law that:
\end{enumerate}
\end{enumerate}
\end{document}
The first \end{enumerate} got you from being aligned with the T in "The date when the school term...." to being aligned with the (2). You need one more to get you out to align with the b.
If you need to pick up the list from where you left off (3c, 3d, etc.) further down, you can do it using \setcounter so that it doesn't start over again at a; here's an example:
\documentclass[]{article}
\begin{document}
\begin{enumerate}
\item text
\item text
\item text
\end{enumerate}
Text Text Text
\begin{enumerate}
\setcounter{enumi}{3}
\item pickup where left off
\item text
\end{enumerate}
\end{document}
I wrote a small macro called unclip.
Used with all lowercase, it will end a list, write the given contents, and resume the list.
Used with uppercase U, it will gather the enumeration-number before writing the contents and restore it when resuming the list.
\newcommand{\unclip}[2][enumerate]{\end{#1}#2\begin{#1}}%
\makeatletter
\newcommand{\Unclip}[2][enumerate]{%
\#ifundefined{c#saveenum#\romannumeral\#enumdepth}% create temporary counter
{\newcounter{saveenum#\romannumeral\#enumdepth}}{}%
\setcounter{saveenum#\romannumeral\#enumdepth}% store item number
{\value{enum\romannumeral\#enumdepth}}%
\end{#1}#2\begin{#1}% end list, write content, resume
\setcounter{enum\romannumeral\#enumdepth}% restore item number
{\value{saveenum#\romannumeral\#enumdepth}}}%
\makeatother
You can stack it for multiple levels. Be aware that it may give an error if you stack it, unless you use an \item[] after each inner call. It will still compile though.
Extensive example:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\newcommand{\unclip}[2][enumerate]{\end{#1}#2\begin{#1}}%
\makeatletter
\newcommand{\Unclip}[2][enumerate]{%
\#ifundefined{c#saveenum#\romannumeral\#enumdepth}% create temporary counter
{\newcounter{saveenum#\romannumeral\#enumdepth}}{}%
\setcounter{saveenum#\romannumeral\#enumdepth}% store item number
{\value{enum\romannumeral\#enumdepth}}%
\end{#1}#2\begin{#1}% end list, write content, resume
\setcounter{enum\romannumeral\#enumdepth}% restore item number
{\value{saveenum#\romannumeral\#enumdepth}}}%
\makeatother
\begin{document}
\begin{itemize}
\item TestItem A
\begin{description}
\item[preparation] No Item-number yet, so only smallercase unclip
\item[test] and action:
\unclip[description]{This should be below \textit{TestItem A}}
\item[Test] And now inside a enumeration:
\begin{enumerate}
\item One
\item Two
\Unclip{This should be under \textit{Test}}
\item Three
\Unclip{But now we are stacking, by calling
\textbackslash Unclip\{\textbackslash unclip[description]\{text\}\}
\unclip[description]{so this should be under \textit{TestItem A}
\\Be aware it will raise an error, eventhough it works fine.
\unclip[itemize]{And while you can have text in front of an inner unclip,
doing it the other way round would seriously fuck up your layout.}}}
\item Four
\begin{enumerate}
\item Unus
\item Duo
\item Tres
\Unclip{Yes, you can \Unclip{unclip multiple
\unclip[description]{levels just fine.
\unclip[itemize]{Still works. :-)}}}}
\item Quattuor
\Unclip{\Unclip{\unclip[description]{\unclip[itemize]{By the way:}
\item[]You can get rid of the errors,}\item[and] stack it back in}
\item[] by using \textbackslash item[] after the inner unclips}
\item Quinque
\item \dots
\end{enumerate}
\end{enumerate}
\end{description}
\item TestItem B
\end{itemize}
\end{document}
I hope it helps.
Cheers.
You have to use \noindent
You just have an indent ;)

! LaTeX Error: Something's wrong--perhaps a missing \item

\documentclass[11pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphics}
\usepackage {epsfig}
\usepackage{fancyhdr}
\linespread{1.4}
\setlength{\topmargin}{-0.4in}
\setlength{\topskip}{0.3in} % between header and text
\setlength{\textheight}{9.5in} % height of main text
\setlength{\textwidth}{6in} % width of text
%\setlength{\leftmargin}{-0.6in}
%\setlength{\oddsidemargin}{0.75in} % odd page left margin
%\setlength{\evensidemargin}{0.75in} % even page left margin
\addtolength{\evensidemargin}{-0.4in}
\addtolength{\oddsidemargin}{-0.4in}
\addtolength{\textwidth}{0.4in}
\begin{document}
\renewcommand\bibname{References}
\begin{titlepage}
\input{TitlePage}
\end{titlepage}
\pagenumbering{gobble}
\newpage
\pagenumbering{roman}
%\tableofcontents
\chapter*{
\begin{center}
{Abstract}
\end{center}
}
\begin{quotation}
\paragraph{}
Bank are providing mobile application to their customer. We are developing
banking application using Location Based Encryption. As compare to current
banking application which are location independent,
\\
\textbf{Keywords:}
Enter Keyword here.......
\end{quotation}
\newpage
\pagenumbering{arabic}
\pagestyle{fancy}
\fancyhead{} % clear all fields
\fancyhead[RO,LE]{}
\renewcommand\headrule{}
\rhead{PROJECT NAME}
\renewcommand{\footrulewidth}{0.4pt}
\fancyfoot[RE,LO]{P.E.O COLLEGE}
\input{intro}
%\input{Literature_Survey}
\input{table}
%\input{problmstmt}
\input{scope}
%\input{future}
\input{conclusion}
\input{ref}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I have this latex code. But when I try to compile it it gives me an error saying :
! LaTeX Error: Something's wrong--perhaps a missing \item.See the
LaTeX manual or LaTeX Companion for explanation.Type H for
immediate help....
This error is on line:
\end{quotation}
Why am I getting this error? I haven't added any \item on the line where I'm getting the error.
The \paragraph and \\ instructions in the quotation do not make much sense. I guess that you meant something like this:
\begin{quotation}
\noindent
Banks are providing mobile applications to their customer. We are developing a
banking application using \emph{Location Based Encryption}. Compared to current
banking applications, which are location independent, \ldots
\paragraph{Keywords:} bank, application, encryption, location, mobile.
\end{quotation}

Environment inside a longtable with LaTeX

I would like to create a new environment to print a header and a footer between sections of a table.
I did this:
\documentclass{article}
\usepackage{longtable}
\newenvironment{env}{Heading&&& \\}{\hline \\}
\begin{document}
\begin{longtable}{p{7cm}lrr}
\begin{env}
Content&b&c&d
\end{env}
\end{longtable}
\end{document}
but I get insulted by the compiler. See here for the complete output.
Does someone see the problem?
There are two problems here. First, you need an \\ at the end of the "Content&b&c&d" line. Second, environments don't work inside tabular/longtable — that's where most of your error messages are coming from. It may be possible to diddle them into working, but it's way beyond my TeX-fu. This is the best I can come up with:
\documentclass{article}
\usepackage{longtable}
\newcommand{\startenv}{Heading\tabularnewline}
\newcommand{\stopenv}{\hline\tabularnewline}
\begin{document}
\begin{longtable}{p{7cm}lrr}
\startenv
Content&b&c&d \\
\stopenv
\end{longtable}
(It is not strictly necessary to use \tabularnewline instead of \\, but it will avoid headaches if you ever mix this with other environments that use \\ for their own purposes.)

Resources