LaTeX forum ⇒ TeXworkshow to format better when we have tables

Information and discussion about TeXworks, an integrated LaTeX environment for several platforms
yaozhao
Posts: 57
Joined: Sat Oct 27, 2018 10:38 pm

how to format better when we have tables

Postby yaozhao » Fri Nov 09, 2018 5:44 am

\subsection{Q11}
Imagine that the interest rate on your savings account was 1\% per year and inflation was 2\%per year. After 1 year, how much would you be able to buy with the money in this account?

\begin{table} 
\centering 
\caption{Q11} 
\scalebox{0.7}{
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{cc}}
\hline\hline
            &\multicolumn{2}{c}{q11}  \\
            &           b&         pct\\
\hline
Correct Answer&         604&    72\\
Wrong Answer&          115&    14\\
Don't know&	122&	 	14\\
Total       &         841&         100\\
\hline
\(N\)       &         841&            \\
\hline\hline
\end{tabular}
}
}
\label{T2} 
\end{table}

\subsection{Q12}
If interest rates rise, what will typically happen to bond prices?

\begin{table} 
\centering 
\caption{Q12} 
\scalebox{0.7}{
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{cc}}
\hline\hline
            &\multicolumn{2}{c}{q12}  \\
            &           b&         pct\\
\hline
Correct Answer&         220&    26\\
Wrong Answer&          316&    38\\
Don't know&	305&	 	36\\
Total       &         841&         100\\
\hline
\(N\)       &         841&            \\
\hline\hline
\end{tabular}
}
}
\label{T2} 
\end{table}


I want to each table below its corresponding section. In other words, each subsection has one table below. Then a new subsection, its table, a new subsection, its table......

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Stefan Kottwitz
Site Admin
Posts: 9880
Joined: Mon Mar 10, 2008 9:44 pm

how to format better when we have tables

Postby Stefan Kottwitz » Sat Nov 10, 2018 1:38 am

You can load the placeins package:

\usepackage{placeins}

Then, use the command \FloatBarrier before a subsection so no table can float beyond the next subsection heading.

If you really want to fix table positions, then, instead of above, add

\usepackage{float}

and use the [H] option, such as

\begin{table}[H]

Stefan
LaTeX.org admin


Return to “TeXworks”

Who is online

Users browsing this forum: No registered users and 2 guests