Graphics, Figures & Tablestabbing and tabular questions

Information and discussion about graphics, figures & tables in LaTeX documents.
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

tabbing and tabular questions

Post by itsmereally »

Hello

I'm having a bit of trouble with a couple of things, and was hoping to get some help.

1. Here I'm trying to align three pairs of lines.

Code: Select all

\documentclass[a4paper,11pt]{article}

\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{MnSymbol}

\sisetup{unitmathrm = mathbf}

\begin{document}

\begin{tabbing}
\textbullet \hspace{0.1cm} 1 micrometre  \= $\equal 1$\si{\mu m} \\
\> $\equal 1 \times 10^{-6}$\si{m} \\[0.3cm]
\textbullet \hspace{0.1cm} 1 nanometre  \= $\equal 1$\si{nm} \\
\> $\equal 1 \times 10^{-9}$\si{m} \\[0.3cm]
\textbullet \hspace{0.1cm} $2.50$ KiloWatts \= $\equal 2.50$\si{kW} \\
\> $\equal \times 10^{3}$\si{W} \\
\end{tabbing}

\end{document}
Is there anyway to line up the top two pairs with the equals signs of the bottom pair? What I'd like is all six equals signs inline, and the bottom pair staying where it currently is.

2. With this one, I'm trying to create a table with defined column widths.

Code: Select all

\documentclass[a4paper,11pt]{article}

\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{MnSymbol}

\sisetup{unitmathrm = mathbf}

\begin{document}

\framebox[0.5cm]{a} \framebox[8.5cm][l]{Acceleration} \framebox[3cm]{\si{ms^{-2}}} \\

\begin{flushleft}
\begin{tabular}{|c| @{\extracolsep{3.2cm}} l| @{\extracolsep{0.1cm}} c|}
\hline
{\textbf{Sym.}} & \textbf{Repesentation} & \textbf{Units} \\
\hline
a & Accelerationhhhhhhhhhhhhhhhhhhhhhh & \si{ms^{-2}} \\
\hline
\end{tabular}
\end{flushleft}

\begin{flushleft}
\begin{tabular}{|c|l|c|}
\hline
{\textbf{Sym.}} & \textbf{Repesentation} & \textbf{Units} \\
\hline
a & Accelerationhhhhhhhhhhhhhhhhhhhhhh & \hspace{2cm} \si{ms^{-2}} \\
\hline
\end{tabular}
\end{flushleft}

\begin{flushleft}
\begin{tabular}{| m{0.8cm}| m{8.5cm}| m{2cm}|}
\hline
{\textbf{Sym.}} & \textbf{Repesentation} & \textbf{Units} \\
\hline
a & Accelerationhhhhhhhhhhhhhhhhhhhhhh & \hspace{2cm} \si{ms^{-2}} \\
\hline
\end{tabular}
\end{flushleft}

\end{document}
I've tried numerous things, but still can't work it out. I'd normally do something like this in Excel, but I'll be adding things from time to time, so I'd prefer something of this form for easy editting.

I'm trying to get a table, from the left page margin to the right, with three columns, the first with mathematical symbols, the second with information on what the symbols represent and the third with the units of the symbol. The first and third columns needs to be centred. The second column needs to be left aligned, but it's title needs to be centred.

I want to set the widths of the table itself and also the columns. I haven't got any idea what to try now.

Could anyone help me with either of these?

Thanks.
Last edited by itsmereally on Sat Sep 11, 2010 7:27 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

tabbing and tabular questions

Post by frabjous »

For your first problem, if you want to stick with a tabbing environment, you should only set the tab stop at the beginning, once, using the widest entry. If the widest entry isn't first, you'll need to put it in twice, and then use \kill to prevent that line from being typeset twice. Probably clearer if I show you:

Code: Select all

\documentclass[a4paper,11pt]{article}

\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{MnSymbol}

\sisetup{unitmathrm = mathbf}

\begin{document}

\begin{tabbing}
\textbullet \hspace{0.1cm} $2.50$ KiloWatts \= $\equal 2.50$\si{kW} \kill\\
\textbullet \hspace{0.1cm} 1 micrometre  \> $\equal 1$\si{\mu m} \\
\> $\equal 1 \times 10^{-6}$\si{m} \\[0.3cm]
\textbullet \hspace{0.1cm} 1 nanometre  \> $\equal 1$\si{nm} \\
\> $\equal 1 \times 10^{-9}$\si{m} \\[0.3cm]
\textbullet \hspace{0.1cm} $2.50$ KiloWatts \> $\equal 2.50$\si{kW} \\
\> $\equal \times 10^{3}$\si{W} \\
\end{tabbing}

\end{document}
(This is could also be done with something like the align environment from amsmath.)

If I have time later, I'll give some help with your second problem, but I'm currently late for an appointment and don't have time to work on it right now. Reading the LaTeX wikibook on tables will no doubt provide some help, however.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

tabbing and tabular questions

Post by frabjous »

OK, for your second question, this is my best guess at what you want, though I wasn't entirely sure if it captures everything. Perhaps it'll help, though.

Code: Select all

\noindent\begin{tabular}{|>{\centering\begin{math}}m{0.8cm}<{\end{math}} | m{8.5cm} | >{\centering\arraybackslash}m{2cm}|}\hline
\textbf{Sym.} & \centering\textbf{Representation} & \textbf{Units} \\ \hline
a & Acceleration & \si{ms^{-2}} \\ \hline
\end{tabular}
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Re: tabbing and tabular questions

Post by itsmereally »

Wow! Thanks for the replies. :o

Both of those are brilliant. They're exactly what I was after.

I did look at the Wikibook for this, but I really didn't understand what was going on with those commands that set the table parameters. I'm still not too sure, but I can use the table you've done for me to experiment.

The two things you've done are exactly what I asked for. However, after trying the second one, the table, I have another question.

Is there any way to define the height of the rows in the table? I noticed the superscript in the example touches the line below the titles.

Thanks again.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

tabbing and tabular questions

Post by frabjous »

itsmereally wrote: I did look at the Wikibook for this, but I really didn't understand what was going on with those commands that set the table parameters. I'm still not too sure, but I can use the table you've done for me to experiment.
I have to confess that tables in LaTeX are one thing that I wish were more straightforward. If you have any specific questions, feel free to ask.
Is there any way to define the height of the rows in the table? I noticed the superscript in the example touches the line below the titles.
There are a number of ways, and again, it's not as obvious as it probably should be. You can enter a length after \\ just like you were doing already with your tabbing example, but this seems to have some strange side effects for reasons that I don't really understand myself. In your case, I'd recommend changing the \arraystretch value. So right before the table, put something like:

Code: Select all

\renewcommand*{\arraystretch}{1.2}
This is a multiplier, and it affects all rows of the table. So if you wanted all rows twice as big, make is 2. I have it here as 1.2 times the usual height.
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

tabbing and tabular questions

Post by itsmereally »

frabjous wrote: I have to confess that tables in LaTeX are one thing that I wish were more straightforward. If you have any specific questions, feel free to ask.

There are a number of ways, and again, it's not as obvious as it probably should be. You can enter a length after \\ just like you were doing already with your tabbing example, but this seems to have some strange side effects for reasons that I don't really understand myself. In your case, I'd recommend changing the \arraystretch value. So right before the table, put something like:

Code: Select all

\renewcommand*{\arraystretch}{1.2}
This is a multiplier, and it affects all rows of the table. So if you wanted all rows twice as big, make is 2. I have it here as 1.2 times the usual height.
I copy & pasted that coding, and it works perfectly. Now the table looks exactly how I wanted it. :)

Tables are the most difficult thing I've encountered while learning how to use LaTeX. I'm feeling much better about them now, thanks to your example. As with the other things I've struggled with, I've found examples from people with greater knowledge to be the best help.

Thank you so much for your help. I've spent quite a few hours scouring the internet and the guides I've downloaded, without getting very far.

I may be back with another table question soon, but I'm going to have a go myself first.

Thanks again. :)
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

tabbing and tabular questions

Post by itsmereally »

Well, I've had a go and not got very far.

I'm trying to create a table similar to before. I'd try describing it, but I've done an example on Excel to make things clearer.

Image

Is this even possible in LaTeX?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tabbing and tabular questions

Post by gmedina »

Hi,

try this:

Code: Select all

\documentclass{article} 
\usepackage{multirow}

\begin{document}

\begin{tabular}{|c|l|c|}
  \hline
  \multirow{2}{*}{J} & Planck Constant & \multirow{2}{*}{Js}\\
  \cline{2-2}
  & $6.66\times 10^{64}$ & \\
  \hline
\end{tabular}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
itsmereally
Posts: 32
Joined: Sun Jul 25, 2010 11:15 pm

Re: tabbing and tabular questions

Post by itsmereally »

Thanks for the reply. :)

I've tweaked your coding a little bit, using frabjous' help from before, and now I've got exactly what I wanted.

Thank you very much. My document is looking great now. :)

Out of curiosity, how exactly does the \cline bit work? I tried experimenting with it, but still can't figure it out. I've read about the two "i" and "j" values being the columns that the partial line moves across, but I don't understand how to use it.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tabbing and tabular questions

Post by gmedina »

itsmereally wrote:Thanks for the reply. :)
[...]Out of curiosity, how exactly does the \cline bit work? I tried experimenting with it, but still can't figure it out. I've read about the two "i" and "j" values being the columns that the partial line moves across, but I don't understand how to use it.
You're welcome. Your description of the \cline command is correct. This example could help you understand how it works:

Code: Select all

\documentclass{article}

\begin{document}

\begin{tabular}{llllll}
  \cline{1-6} % hor. line from column 1 to 6 (same as an \hline)
  column1a & column2a & column3a & column4a & column5a & column6a \\
  \cline{1-1}\cline{3-5} % hor. lines: at column one and from column 3 to 5
  column1b & column2b & column3b & column4b & column5b & column6b \\
  \cline{2-4}\cline{6-6} % hor. lines: from column 2 to 4 and at column 6
  column1c & column2c & column3c & column4c & column5c & column6c \\
  \hline
\end{tabular}

\end{document}
\cline (and \hline) can only be used after the format declaration of the table and after the line change command \\.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply