使用网格与表格来创建类似目录的布局

使用网格与表格来创建类似目录的布局

我正在尝试弄清楚如何在 ConTeXt 中设置流体网格,以便目录的所有元素都呈现清晰且可识别的模式。

我阅读的有关网格的内容越多,我就越相信它只在基线上对齐元素,而我需要定义单元格,将它们放在由标题、副标题、项目符号、图片和功能组成的块内。

更接近 HTML 网格的东西:https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout

我想知道是否可以创建更接近这个例子的东西:

网格布局模拟

我最好创建一个表格(就像在 HTML4 时代一样),然后在每个单元格内使用类似“边界框”的东西来创建相对坐标。我无法想象有什么可以将我制作的图形抽象为 ConTeXt 基本命令,谢谢!

答案1

以下东西可能会让您入门。我制作了一张所有员工的照片板,然后滥用了书目系统。这对于目录来说可能也行得通,只要不同的项目看起来或多或少相同。如果不行,那么我建议您提出一个新问题,也许提供更多信息。

请注意,我在这里所做的操作可以很容易地用宏来完成,但使用书目数据库(这里在缓冲区中,但可以在单独的文件中)实际上是将布局和数据分开。我不确定如何做,但我确信也可以将 SQL 数据库与数据一起使用(对于产品目录来说,这可能更方便)。

无论如何,它看起来是这样的:

页面

代码如下所示(如果我忘记从我在工作时制作的照片板上删除或更改某些设置,我很抱歉):

\setupbodyfont[iwona]

\definemeasure[columnseparation][0.4cm]
\definemeasure[tablewidth][(\textwidth - 3\measured{columnseparation})/4]
\definemeasure[figwidth][\measured{tablewidth} - 2\measured{columnseparation}]
\definemeasure[figheight][2.6cm]
\definemeasure[tabletitleheight][1.25cm]
\definemeasure[tabledescriptionheight][1.5cm]
\definemeasure[tabelfigheight][\measured{figheight} + 2\measured{columnseparation}]

\setuplayout
  [backspace=1.5cm,
   topspace=1.5cm,
   margin=0cm,
   header=0cm,
   footer=0cm,
   height=fit,
   width=fit,
   ]

\setupexternalfigures
  [location={local,global,default}]

\useMPlibrary[dum]

\defineexternalfigure
  [catalogfigure]
  [width=\measure{figwidth},
   height=\measure{figheight},
   text=no]

\usecolors[crayola]

\startuseMPgraphic{TableBackground}
  path p ;
  p := unitsquare xyscaled(OverlayWidth, OverlayHeight) ;
  fill p superellipsed 0.97 withcolor "CulturedPearl" ;
  draw p superellipsed 0.97 withcolor "OceanBluePearl" ;
\stopuseMPgraphic

\defineoverlay
  [TableBackground]
  [\useMPgraphic{TableBackground}]

\setupTABLE[width=\measure{tablewidth},offset=\measured{columnseparation},frame=off]
\setupTABLE[r][1][height=\measure{tabletitleheight},align={middle,lohi},style={\definedfont[SansBold*default at 12pt]\setupinterlinespace}]
\setupTABLE[r][2][height=\measure{tabledescriptionheight},align={high},style={\definedfont[Sans*default at 8pt]\setupinterlinespace}]
\setupTABLE[r][3][height=\measure{tabelfigheight},align={middle,lohi}]


\startbuffer[catalog]
@catalogitem {foo1,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo2,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo3,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo4,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo5,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo6,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo7,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo8,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {foo9,
       title = {Test title},
 description = {This is a sentence about the current product.},
}
@catalogitem {cow,
       title = {Mew!},
 description = {This is indeed a cow.},
}
@catalogitem {bar1,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar2,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar3,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar4,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar5,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar6,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar7,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar8,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
@catalogitem {bar9,
       title = {A little longer title},
 description = {This is a sentence about the current product. It continues with some more text.},
}
\stopbuffer

\definebtxdataset
  [catalog]

\usebtxdataset
  [catalog]
  [catalog.buffer]

\definebtx
  [catalog]
  [default=,
   specification=catalog]

\definebtxrendering
  [catalog]
  [specification=catalog,
   group=catalog,
   dataset=catalog,
   method=dataset,
   numbering=no,
   criterium=all]

\startsetups catalog
  \currentlistentrytitle\hskip\measured{columnseparation}
  \allowbreak
\stopsetups

\definelistalternative
  [catalog]
  [renderingsetup=catalog]

\setuplist
  [btx]
  [alternative=catalog]

\startsetups btx:catalog:list:catalogitem
  \startframed
    [offset=overlay,
    boffset=\measure{columnseparation},
    frame=off]
    \startframed
      [background=TableBackground,
      offset=overlay,
      frame=off]
      \bTABLE
        \bTR
          \bTD
            \begstrut\btxflush{title}\endstrut
          \eTD
        \eTR
        \bTR
          \bTD
            \begstrut\btxflush{description}\endstrut
          \eTD
        \eTR
        \bTR
          \bTD
            \externalfigure[\btxflush{tag}][catalogfigure]
          \eTD
        \eTR
      \eTABLE
    \stopframed
  \stopframed
\stopsetups

\starttext

\placebtxrendering[catalog]

\stoptext

这是一些物品的近照。

仔细查看一些条目

相关内容