한 페이지에 비해 표가 너무 길고 열 내용이 수직으로 정렬되지 않았습니다.

한 페이지에 비해 표가 너무 길고 열 내용이 수직으로 정렬되지 않았습니다.

먼저 일반적인 기준에 따라 테이블을 만들어 보았습니다.

\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

위의 코드는 두 가지 문제를 안겨줍니다. 하나 또는 여러 페이지에 맞지 않고 두 번째 열의 내용이 수직으로 정렬되지 않습니다. 그래서 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

두 번째 코드는 긴 표를 여러 페이지에 걸쳐 배치하지만 표의 캡션은 바닥 부분 안에 있습니다. 두 번째 열을 세로로 가운데에 배치하고 캡션을 맨 아래에 배치하고 표를 하나 또는 여러 페이지에 맞추려면 어떻게 해야 합니까? 또한 행 사이에 간격을 추가할 수 있습니까?

편집하다:

내가 사용하는 템플릿을 찾을 수 있습니다여기.

답변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}

여기에 이미지 설명을 입력하세요

관련 정보