首先,我尝试按照正常标准创建一个表格:
\begin{table}[H]
\centering
\begin{tabular}{p{14cm}|c}
\textit{Query} & Grupo \\
\hline
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation; & 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category; & 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand; & 1 \\
\end{tabular}
\caption{Classificação das \textit{queries} do \gls{ssb}}
\label{tab:ssb_queries}
\end{table}
上面的代码给我带来了两个问题,它不适合一个或多个页面,并且第二列的内容未垂直对齐。因此,我尝试longtable
使用table
:
\begin{center}
\begin{longtable}{p{14cm}|c}
\textit{Query} & Group \\
\hline
\endfirsthead
\textit{Query} & Group \\
\hline
\endhead
\hline
\multicolumn{2}{l}{Continue\ldots} \\
\endfoot
\hline
\multicolumn{2}{l}{End} \\
\endlastfoot
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation; & 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category; & 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand; & 1 \\
\caption{Classificação das \textit{queries} do \gls{ssb}} \\
\end{longtable}
\end{center}
第二段代码将长表格放在多页上,但表格的标题位于页脚部分内。如何将第二列垂直居中,将标题放在底部,并将表格放入一页或多页?此外,是否可以在行之间添加间距?
编辑:
我正在使用的模板可以找到这里。
答案1
longtable
这是基于的带有有效页眉和页脚的代码。我还添加了两个包:listings
改进代码格式;并cellspace
在行间插入额外的垂直间距。
\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{listings}
\usepackage{longtable}
\usepackage[column=E]{cellspace}
\lstset{
basicstyle=\small\rmfamily, % \ttfamily or \sffamily
aboveskip=0pt,
belowskip=0pt,
boxpos=t,
language=sql,
keywordstyle=\color{black!30!blue}\bfseries,
columns=flexible,
}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
\begin{longtable}{E{w{l}{12cm}}|c}
\caption{Classificação das \textit{queries} do SSB}\label{tab:ssb_queries} \\
% \caption{Classificação das \textit{queries} do \gls{ssb}}
\textit{Query} & Group \\
\hline\endfirsthead
\textit{Query} & Group \\
\hline\endhead
\hline
\multicolumn{2}{@{}E{l}}{Continue ...}\endfoot
\hline
\multicolumn{2}{@{}E{l}}{End.}\endlastfoot
%%%
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
AND lo_orderdate = d_datekey
AND lo_discount BETWEEN 4
AND 6 AND lo_quantity
BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
AND lo_orderdate = d_datekey
AND lo_discount BETWEEN 4
AND 6 AND lo_quantity
BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
\end{longtable}
\end{document}
编辑。如果您喜欢不同的垂直对齐方式,只需更改 的值即可boxpos
。例如,我假设m
中间对齐方式:
\lstset{
% ...
boxpos=m, % t for top or b for bottom alignment
% ...
}
我还假设您会希望标题位于表格底部的最后一页。您必须将和移动\caption
到\label
以结尾的块中\endlastfoot
。以下是代码片段:
% ...
\begin{longtable}{E{w{l}{12cm}}|c}
\textit{Query} & Group \\
\hline\endfirsthead
\textit{Query} & Group \\
\hline\endhead
\hline
\multicolumn{2}{@{}E{l}}{Continue ...}\endfoot
\hline
\multicolumn{2}{@{}E{l}}{End.} \\[2ex]
\caption{Classificação das \textit{queries} do SSB}
\label{tab:ssb_queries}\endlastfoot
%%%
% ...
其余代码保持不变。
答案2
这是一个longtable
基于此的解决方案,它通过使用包的线条绘制宏booktabs
(具体来说,\midrule
、\addlinespace
和\bottomrule
)来努力使表格具有更开放的“外观”,而不是\hline
。它还省去了完全对齐。
\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters as needed
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\providecommand\gls[1]{#1} % ??
% new:
\usepackage{longtable,array,booktabs}
\begin{document}
\begin{longtable}{@{} >{\raggedright\arraybackslash}p{14cm} r @{}}
%% headers and footers
\caption{Classificação das \textit{queries} do \gls{ssb}} \\
\textit{Query} & Group \\
\midrule
\endfirsthead
\tablename\ \thetable, continued\\[1ex]
\textit{Query} & Group \\
\midrule
\endhead
\midrule
\multicolumn{2}{r@{}}{Continue\dots} \\
\endfoot
\bottomrule
%\multicolumn{2}{l}{End} \\
\endlastfoot
%% body of longtable
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
\addlinespace
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25;
& 1 \\
\addlinespace
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation;
& 1 \\
\addlinespace
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category;
& 1 \\
\addlinespace
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand;
& 1 \\
\end{longtable}
\end{document}
答案3
尝试longtblr
使用tabularray
包。使用它的 MWE 更简短、更清晰:
\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\begin{document}
\begin{longtblr}[
caption = {Classificação das \textit{queries} do},% \gls{ssb}
label = {longtab:?}
]{hline{2,Z} = {solid}, vline{2} = solid,
colspec = {X[j] c},
rowsep=3pt,
rowhead = 1
}
\textit{Query}
& Group \\
%%%% table body
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25;
& 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation;
& 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category;
& 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand;
& 1 \\
\end{longtblr}
\end{document}
答案4
@Celdor 的回答非常有趣,所以我尝试在我的回答中实现他的方法。我很快意识到这并不容易,因为列表不能直接插入tabularray
单元格中,即使你使用verb
选项(它只支持短\verb
命令)。
在@Paul Gaborit 的帮助下回答在我寻求帮助时,以下是解决您问题的可能方法:
\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
basicstyle=\small\sffamily,
aboveskip=-7pt,
belowskip=-2pt,
language=sql,
keywordstyle=\color{black!30!blue}\bfseries,
columns=flexible,
}
\begin{document}
\begin{filecontents*}[force]{\jobname-sql-1.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d\_yearmonthnum = 199401
AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4
AND 6
AND lo\_quantity BETWEEN 26 AND 35;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-2.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue F
ROM lineorder, dwdate
WHERE d\_year = 1993
AND lo\_orderdate = d\_datekey
AND lo\_discount BETWEEN 1
AND 3
AND lo\_quantity < 25;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-3.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d\_weeknuminyear = 6
AND lo\_orderdate = d\_datekey
AND d\_year = 1994
AND lo\_discount BETWEEN 5
AND 7
AND lo\_quantity BETWEEN 26 AND 35;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-4.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_category = 'MFGR\#12'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND s\_region = 'AMERICA'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-5.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_brand BETWEEN 'MFGR\#2221'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND 'MFGR\#2228' AND s\_region = 'ASIA'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-6.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_brand = 'MFGR\#2221'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND s\_region = 'EUROPE'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-7.tex}
SELECT c\_nation, s\_nation, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'ASIA'
AND s\_region = 'ASIA'
AND d\_year >= 1992
AND d\_year <= 1997
GROUP BY c\_nation, s\_nation, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-8.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE c\_nation = 'UNITED STATES'
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND s\_nation = 'UNITED STATES'
AND d\_year >= 1992
AND d\_year <= 1997
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-9.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE d\_year >= 1992
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5')
AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5')
AND d\_year <= 1997
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-10.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE d\_yearmonth = 'Dec1997'
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5')
AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5')
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-11.tex}
SELECT d\_year, c\_nation,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_region = 'AMERICA'
AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2')
GROUP BY d\_year, c\_nation
ORDER BY d\_year, c\_nation;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-12.tex}
SELECT d\_year, s\_nation, p\_category,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_region = 'AMERICA'
AND (d\_year = 1997 OR d\_year = 1998)
AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2')
GROUP BY d\_year, s\_nation, p\_category
ORDER BY d\_year, s\_nation, p\_category;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-13.tex}
SELECT d\_year, s\_city, p\_brand,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_nation = 'UNITED STATES'
AND (d\_year = 1997 OR d\_year = 1998)
AND p\_category = 'MFGR\#14'
GROUP BY d\_year, s\_city, p\_brand
ORDER BY d\_year, s\_city, p\_brand;
\end{filecontents*}\\
\noindent%
\begin{longtblr}[
caption = {Classificação das \textit{queries} do},% \gls{ssb}
label = {longtab:?}
]{hline{2,Z} = {solid},
colspec = {X[j,m] | c},
row{1} = {font=\itshape},
rowsep=0pt,
rowhead=1}
rowhead=1}
\lstinputlisting{\jobname-sql-1.tex} & 1 \\
\lstinputlisting{\jobname-sql-2.tex} & 1 \\
\lstinputlisting{\jobname-sql-3.tex} & 1 \\
\lstinputlisting{\jobname-sql-4.tex} & 1 \\
\lstinputlisting{\jobname-sql-5.tex} & 1 \\
\lstinputlisting{\jobname-sql-6.tex} & 1 \\
\lstinputlisting{\jobname-sql-7.tex} & 1 \\
\lstinputlisting{\jobname-sql-8.tex} & 1 \\
\lstinputlisting{\jobname-sql-9.tex} & 1 \\
\lstinputlisting{\jobname-sql-10.tex} & 1 \\
\lstinputlisting{\jobname-sql-11.tex} & 1 \\
\lstinputlisting{\jobname-sql-12.tex} & 1 \\
\lstinputlisting{\jobname-sql-13.tex} & 1 \\
\end{longtblr}
\end{document}