表が 1 ページに対して長すぎるため、列の内容が垂直方向に揃っていません

表が 1 ページに対して長すぎるため、列の内容が垂直方向に揃っていません

まず、通常の基準で表を作成してみました。

\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}

pdf_1

上記のコードには 2 つの問題があります。1 つまたは複数のページに収まらないことと、2 番目の列の内容が垂直に揃っていないことです。そのため、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}

pdf_2

pdf_3

2 番目のコードでは、長い表が複数のページにわたって配置されますが、表のキャプションはフッター部分内にあります。2 番目の列を垂直に中央揃えし、キャプションを下部に配置して、表を 1 ページまたは複数のページに収めるにはどうすればよいでしょうか。また、行間にスペースを追加することは可能ですか。

編集:

私が使用しているテンプレートはここ

答え1

longtableヘッダーとフッターが機能する に基づくコードを以下に示します。またlistings、コードのフォーマットを改善し、cellspace行間に余分な垂直間隔を挿入する2 つのパッケージも追加しました。

\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

tabularray@Celdor の回答は非常に興味深いので、彼のアプローチを自分の回答に実装しようとしました。オプションを使用しても、リストをセルに直接挿入できないため、これはそれほど簡単ではないことにすぐに気付きました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}

ここに画像の説明を入力してください

関連情報