시험 문서 클래스의 솔루션 환경 내부 테이블 사용

시험 문서 클래스의 솔루션 환경 내부 테이블 사용

solutiondocumentclass 환경 내부에서 테이블 환경을 사용하려고 합니다 exam. 불행하게도 이것은 명시된 대로 작동하지 않습니다이것이후 질문 table도 부동 소수점입니다.

솔루션 환경은 내부적으로 \vbox를 사용하므로 결과적으로 이 환경 내에서는 부동 소수점이 허용되지 않습니다. 부동 환경 테이블을 사용하는 대신 중앙 환경을 사용할 수 있습니다.

solution그들은 환경 외부에서 작동하기 때문에 \begin{table} ... \end{table}솔루션 외부에 있고 내부가 \begin{center}...\end{center}.

다행히도이것게시물은 귀하가 환경 내부에 있는지 여부를 쉽게 알 수 있음을 보여줍니다 solution. 나는 이것을 테스트했고 작동합니다.
그러나 문서 클래스에 적용해야 하는 문서가 exam많고 다른 문서 클래스에서도 사용되기 때문에 이상적으로는 새 환경을 만들지 않고 table발생한 것과 유사한 환경을 적용합니다.여기또는figure여기테이블 형식 환경으로. 이것은 지금까지 내 코드입니다.
업데이트:이유는 모르겠지만 오류 \center대신에 \begin{center}오류가 사라지고 선택적 인수를 처리할 수 있는 방법도 허용됩니다.table

\documentclass{exam}

\let\oldtable\table
\let\endoldtable\endtable

\renewenvironment{table}[1][h]
{\ifinner \center    \else  \oldtable[#1] \fi}
{\ifinner \endcenter \else  \endoldtable  \fi}

\begin{document}

\begin{questions} %error is no \question 
\printanswers

\question{Question featuring a table environment}

\begin{table}[h]
    \begin{tabular}{|ll|}
        Question & in  \\
        Question & part \\
    \end{tabular}
\end{table}


\begin{solution}
Solution featuring a table environment

    \begin{table}[h]
        \begin{tabular}{|ll|}
            Solution & in  \\
            Solution & part \\
        \end{tabular}
    \end{table}

\end{solution}

\end{questions}

\end{document}

그러나 나는 올바른 매개변수를 처리하지 않고 있다는 점을 우려합니다 table. 왜냐하면 이것이 오류: Unknown float option `['로 이어지기 때문입니다. \begin{테이블}[

이 솔루션은 "내부" 외부에서 작동하며 의 선택적 인수를 처리할 수 있습니다 table. 그러나 \ifinner이것이 사실이라면 오류가 발생합니다.

추가 } 또는 잊어버린 것입니다. \탁자}

table환경에 따라 적응하는 방법에 대한 제안이 있는 사람이 있습니까 ?

매우 감사합니다

답변1

다른 사람이 이 문제에 직면한 경우 해결책을 찾았으며 답변으로 여기에 게시했습니다. 돌이켜보면 분명한 문제는 \ifinner떠다니는 환경이기 때문에 처음에는 작동하지만 시작하자마자 \table더 이상 작동하지 않는다는 것입니다. 따라서 \endcenter도달할 수 없습니다. 나는 몇 가지 대안을 시도했고 가장 쉬운 방법은 ifinner수정된 값에 table도달했는지 확인하는 사용자 정의 부울을 정의하고 이를 사용하여 부울을 설정하는 것입니다. 그런 \endtable다음 이 부울을 사용하여 올바르게 종료할 수 있습니다.

\let\oldtable\table
\let\endoldtable\endtable
\newif\ifinsidefloatingenv  %set boolean for 
\insidefloatingenvfalse     %not necessary but to be sure its false

\renewenvironment{table}[1][h]
{\ifinner               \center \insidefloatingenvtrue     \else    \oldtable[#1]   \fi}
{\ifinsidefloatingenv   \endcenter \insidefloatingenvfalse \else    \endoldtable    \fi}

관련 정보